Skip to content

Commit

Permalink
App now launches opening a blank page. Reader deletes edited Page if …
Browse files Browse the repository at this point in the history
…empty.
  • Loading branch information
aiman-al-masoud committed Jul 9, 2021
1 parent 5f77ca7 commit d4e4c9b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,11 @@ public void addListener(PageListener listener) {

@Override
public String getPreview() {
return getText().substring(0, Math.min(10, getText().length()))+"...";
try{
return getText().substring(0, Math.min(10, getText().length()))+"...";
}catch (NullPointerException e){
}
return "...";
}

/**
Expand Down
19 changes: 11 additions & 8 deletions app/src/main/java/com/luxlunaris/noadpadlight/ui/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import com.luxlunaris.noadpadlight.R;
import com.luxlunaris.noadpadlight.control.classes.Notebook;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
Expand Down Expand Up @@ -40,17 +41,19 @@ protected void onCreate(Bundle savedInstanceState) {

CONTEXT = this.getApplicationContext();

goToPagesButton = findViewById(R.id.goToPagesList);
goToPagesButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

}
});
//make the pages-listing activity
Intent goToPagesIntent = new Intent(this, PagesActivity.class);
startActivity(goToPagesIntent);


Intent intent = new Intent(this, PagesActivity.class);
startActivity(intent);
//jump to a blank page
//TODO: replace hardcoded true with persistent setting
if(true){
Intent intent = new Intent(this, ReaderActivity.class);
intent.putExtra("PAGE", Notebook.getInstance().newPage());
startActivity(intent);
}


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,29 @@ private void jumpToPosition(int position){
* Save the progress when exiting from the activity
*/
@Override
protected void onDestroy() {
super.onDestroy();
Toast.makeText(this, "saved", Toast.LENGTH_SHORT).show();
page.setText(textView.getText().toString());
//save the current position
protected void onPause() {
super.onPause();

//get the edited text from the edittext view
String editedText = textView.getText().toString();

//if the edited text is empty, delete the Page
if(editedText.trim().isEmpty()){
page.delete();
return;
}

//save the current position on the page
page.savePosition(textView.getSelectionStart());

//if the edited text doesn't differ from the text in the page, don't re-write it
if(editedText.equals(page.getText())){
return;
}

//else save the new text
page.setText(editedText);
Toast.makeText(this, "saved", Toast.LENGTH_SHORT).show();
}


Expand Down

0 comments on commit d4e4c9b

Please sign in to comment.