Skip to content

Commit

Permalink
Some minor refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
aiman-al-masoud committed Jul 31, 2021
1 parent ef93659 commit 11c7d0a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 31 deletions.
50 changes: 20 additions & 30 deletions app/src/main/java/com/luxlunaris/noadpadlight/ui/PagesActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
Expand All @@ -17,7 +16,6 @@
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Lifecycle;

import com.luxlunaris.noadpadlight.R;
import com.luxlunaris.noadpadlight.control.classes.Notebook;
Expand Down Expand Up @@ -90,7 +88,8 @@ protected void onCreate(Bundle savedInstanceState) {
loadNextPagesBlock();

//defines what the activity does when scrolling occurs
setOnScrollAction();
ScrollView scrollView = findViewById(R.id.scroll_view_pages);
scrollView.setOnScrollChangeListener(new ScrollHandler());

//to keep track of changes while in the background
changes = new ProxyNotebookListener();
Expand All @@ -99,33 +98,33 @@ protected void onCreate(Bundle savedInstanceState) {
notebook.setListener(this);
}


/**
* Defines the scroll behavior of this activity
* Used to add more pages when you scroll all the
* way down.
*/
@RequiresApi(api = Build.VERSION_CODES.M)
private void setOnScrollAction(){
ScrollView scrollView = findViewById(R.id.scroll_view_pages);
scrollView.setOnScrollChangeListener(new View.OnScrollChangeListener() {
@Override
public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {

//if can't scroll vertically anymore: bottom reached
if(!v.canScrollVertically(1)){
class ScrollHandler implements View.OnScrollChangeListener{

//load no new pages if the user is currently running a query
if(isSearching){
return;
}
@Override
public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
//if can't scroll vertically anymore: bottom reached
if(!v.canScrollVertically(1)){

loadNextPagesBlock();
//load no new pages if the user is currently running a query
if(isSearching){
return;
}

loadNextPagesBlock();
}
});

}
}





/**
* Ensures that there is ONE and only ONE fragment for each Page in the fragments list.
* @param page
Expand Down Expand Up @@ -244,16 +243,6 @@ private void removeFragment(Fragment fragment){
}


/**
* Deletes a page and its corresponding fragment
* @param page
*/
private void deletePage(Page page){
removeFragment(page);
page.delete();
}


/**
* Create the toolbar menu for this activity
* @param menu
Expand Down Expand Up @@ -344,7 +333,8 @@ public boolean onMenuItemClick(MenuItem item) {
case R.id.delete:

for(Page page : notebook.getSelected()){
deletePage(page);
//delete the page (the fragment will automatically be removed too through the callback method "onDeleted")
page.delete();
}
break;
case R.id.compact:
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/menu/edit_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

<item
android:id="@+id/delete"
android:title="delete" />
android:title="delete"
/>

<item
android:id="@+id/compact"
android:title="compact" />
Expand Down

0 comments on commit 11c7d0a

Please sign in to comment.