Skip to content

add data loss functionality to issue fragment base #1175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions app/src/main/java/com/gh4a/fragment/IssueFragmentBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.Parcelable;
Expand Down Expand Up @@ -74,6 +75,8 @@
import io.reactivex.Single;
import retrofit2.Response;

import static android.content.Context.MODE_PRIVATE;

public abstract class IssueFragmentBase extends ListDataBaseFragment<TimelineItem> implements
View.OnClickListener, TimelineItemAdapter.OnCommentAction,
ConfirmationDialogFragment.Callback,
Expand Down Expand Up @@ -228,18 +231,36 @@ public void onRefresh() {
super.onRefresh();
}

private SharedPreferences spGen;

private boolean isSend;

@Override
public void onResume() {
super.onResume();
mImageGetter.resume();
mAdapter.resume();
spGen = getActivity().getSharedPreferences("IssueFragmentBase", MODE_PRIVATE);
if(spGen.getString("editRepoOwner", "").equals(mRepoOwner) && spGen.getString("editRepoName", "").equals(mRepoName)) {
addText(spGen.getString("editMessage", ""));
}
isSend = false;
}

@Override
public void onPause() {
super.onPause();
mImageGetter.pause();
mAdapter.pause();
SharedPreferences.Editor spGenEditor = spGen.edit();
spGenEditor.putString("editRepoOwner", mRepoOwner);
spGenEditor.putString("editRepoName", mRepoName);
if (isSend) {
spGenEditor.putString("editMessage", "");
} else {
spGenEditor.putString("editMessage", mBottomSheet.getText().toString());
}
spGenEditor.commit();
}

@Override
Expand Down Expand Up @@ -561,6 +582,7 @@ public void onEditorTextSent() {
// reload comments
if (isAdded()) {
reloadEvents(false);
isSend = true;
}
getActivity().setResult(Activity.RESULT_OK);
}
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com/gh4a/widget/EditorBottomSheet.java
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,13 @@ private Editable getCommentText() {
return mBasicEditor.getText();
}

public Editable getText() {
if (isInAdvancedMode()) {
return mAdvancedEditor.getText();
}
return mBasicEditor.getText();
}

private void setAdvancedEditorVisible(boolean visible) {
mAdvancedEditorContainer.setVisibility(visible ? View.VISIBLE : View.GONE);
mBasicEditorScrollView.setVisibility(visible ? View.GONE : View.VISIBLE);
Expand Down