Fixed file opening splash screen
This commit is contained in:
parent
1ea93a2cdf
commit
fb0bf7ab5f
7 changed files with 67 additions and 31 deletions
|
@ -20,8 +20,6 @@
|
|||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".view.activity.MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.EDIT" />
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
|
@ -39,6 +37,7 @@
|
|||
<data android:host="*" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".view.activity.MainActivity"></activity>
|
||||
|
||||
<provider
|
||||
android:name="android.support.v4.content.FileProvider"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.wbrawner.simplemarkdown;
|
||||
|
||||
import com.wbrawner.simplemarkdown.view.activity.MainActivity;
|
||||
import com.wbrawner.simplemarkdown.view.activity.SplashActivity;
|
||||
import com.wbrawner.simplemarkdown.view.fragment.EditFragment;
|
||||
import com.wbrawner.simplemarkdown.view.fragment.PreviewFragment;
|
||||
|
||||
|
@ -17,6 +18,7 @@ import dagger.Component;
|
|||
public interface AppComponent {
|
||||
void inject(MarkdownApplication application);
|
||||
void inject(MainActivity activity);
|
||||
void inject(SplashActivity activity);
|
||||
void inject(EditFragment fragment);
|
||||
void inject(PreviewFragment fragment);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package com.wbrawner.simplemarkdown.presentation;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.wbrawner.simplemarkdown.view.MarkdownEditView;
|
||||
import com.wbrawner.simplemarkdown.view.MarkdownPreviewView;
|
||||
|
||||
|
@ -12,6 +15,7 @@ import java.io.InputStream;
|
|||
public interface MarkdownPresenter extends LifecyclePresenter {
|
||||
void loadMarkdown(String filePath);
|
||||
void loadMarkdown(InputStream in);
|
||||
void loadFromUri(Context context, Uri fileUri);
|
||||
void loadTempMarkdown(InputStream in, OnTempFileLoadedListener listener);
|
||||
void setEditView(MarkdownEditView editView);
|
||||
void setPreviewView(MarkdownPreviewView previewView);
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
package com.wbrawner.simplemarkdown.presentation;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.provider.OpenableColumns;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.commonsware.cwac.anddown.AndDown;
|
||||
import com.wbrawner.simplemarkdown.R;
|
||||
import com.wbrawner.simplemarkdown.model.MarkdownFile;
|
||||
import com.wbrawner.simplemarkdown.view.MarkdownEditView;
|
||||
import com.wbrawner.simplemarkdown.view.MarkdownPreviewView;
|
||||
|
@ -147,4 +154,24 @@ public class MarkdownPresenterImpl implements MarkdownPresenter {
|
|||
public void setMarkdown(String markdown) {
|
||||
file.setContent(markdown);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadFromUri(Context context, Uri fileUri) {
|
||||
try {
|
||||
InputStream in =
|
||||
context.getContentResolver().openInputStream(fileUri);
|
||||
Cursor retCur = context.getContentResolver()
|
||||
.query(fileUri, null, null, null, null);
|
||||
if (retCur != null) {
|
||||
int nameIndex = retCur
|
||||
.getColumnIndex(OpenableColumns.DISPLAY_NAME);
|
||||
retCur.moveToFirst();
|
||||
setFileName(retCur.getString(nameIndex));
|
||||
}
|
||||
loadMarkdown(in);
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(context, R.string.file_load_error, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,17 +58,12 @@ public class MainActivity extends AppCompatActivity
|
|||
setContentView(R.layout.activity_main);
|
||||
|
||||
((MarkdownApplication) getApplication()).getComponent().inject(this);
|
||||
setTitle(presenter.getFileName());
|
||||
ButterKnife.bind(this);
|
||||
pager.setAdapter(
|
||||
new EditPagerAdapter(getSupportFragmentManager(), MainActivity.this)
|
||||
);
|
||||
pager.setPageMargin(1);
|
||||
pager.setPageMarginDrawable(R.color.colorAccent);
|
||||
Intent intent = getIntent();
|
||||
if (intent != null && intent.getData() != null) {
|
||||
loadFromUri(intent.getData());
|
||||
}
|
||||
if (getResources().getConfiguration().orientation
|
||||
== Configuration.ORIENTATION_LANDSCAPE) {
|
||||
tabLayout.setVisibility(View.GONE);
|
||||
|
@ -199,7 +194,7 @@ public class MainActivity extends AppCompatActivity
|
|||
builder.show();
|
||||
}
|
||||
|
||||
private String getDocsPath() {
|
||||
public String getDocsPath() {
|
||||
return Environment.getExternalStorageDirectory() + "/" +
|
||||
Environment.DIRECTORY_DOCUMENTS + "/";
|
||||
}
|
||||
|
@ -237,32 +232,12 @@ public class MainActivity extends AppCompatActivity
|
|||
switch (requestCode) {
|
||||
case OPEN_FILE_REQUEST:
|
||||
if (resultCode == RESULT_OK) {
|
||||
loadFromUri(data.getData());
|
||||
presenter.loadFromUri(MainActivity.this, data.getData());
|
||||
}
|
||||
}
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
private void loadFromUri(Uri fileUri) {
|
||||
try {
|
||||
InputStream in =
|
||||
getContentResolver().openInputStream(fileUri);
|
||||
Cursor retCur = getContentResolver()
|
||||
.query(fileUri, null, null, null, null);
|
||||
if (retCur != null) {
|
||||
int nameIndex = retCur
|
||||
.getColumnIndex(OpenableColumns.DISPLAY_NAME);
|
||||
retCur.moveToFirst();
|
||||
presenter.setFileName(retCur.getString(nameIndex));
|
||||
}
|
||||
presenter.loadMarkdown(in);
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(MainActivity.this, R.string.file_load_error, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void requestOpen() {
|
||||
Intent openIntent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
openIntent.setType("text/*");
|
||||
|
@ -281,5 +256,9 @@ public class MainActivity extends AppCompatActivity
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
setTitle(presenter.getFileName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,40 @@
|
|||
package com.wbrawner.simplemarkdown.view.activity;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.OpenableColumns;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.wbrawner.simplemarkdown.MarkdownApplication;
|
||||
import com.wbrawner.simplemarkdown.R;
|
||||
import com.wbrawner.simplemarkdown.presentation.MarkdownPresenter;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* Created by billy on 8/23/17.
|
||||
*/
|
||||
|
||||
public class SplashActivity extends AppCompatActivity {
|
||||
|
||||
@Inject
|
||||
MarkdownPresenter presenter;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
((MarkdownApplication) getApplication()).getComponent().inject(this);
|
||||
Intent intent = getIntent();
|
||||
if (intent != null && intent.getData() != null) {
|
||||
presenter.loadFromUri(getApplicationContext(), intent.getData());
|
||||
}
|
||||
startActivity(new Intent(this, MainActivity.class));
|
||||
finish();
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import com.wbrawner.simplemarkdown.R;
|
|||
import com.wbrawner.simplemarkdown.model.MarkdownFile;
|
||||
import com.wbrawner.simplemarkdown.presentation.MarkdownPresenter;
|
||||
import com.wbrawner.simplemarkdown.view.MarkdownEditView;
|
||||
import com.wbrawner.simplemarkdown.view.activity.MainActivity;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -80,7 +81,9 @@ public class EditFragment extends Fragment implements MarkdownEditView {
|
|||
|
||||
@Override
|
||||
public void showFileSavedMessage() {
|
||||
Toast.makeText(getActivity(), R.string.file_saved, Toast.LENGTH_SHORT).show();
|
||||
String location = ((MainActivity) getActivity()).getDocsPath() + presenter.getFileName();
|
||||
String message = getString(R.string.file_saved, location);
|
||||
Toast.makeText(getActivity(), message, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue