diff --git a/app/build.gradle b/app/build.gradle
index 2e94d55..48a29c4 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -6,8 +6,8 @@ android {
applicationId "com.d3coding.gmusicapi"
minSdkVersion 28
targetSdkVersion 28
- versionCode 26
- versionName "0.24"
+ versionCode 27
+ versionName "0.24.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
diff --git a/app/src/main/java/com/d3coding/gmusicapi/Config.java b/app/src/main/java/com/d3coding/gmusicapi/Config.java
new file mode 100644
index 0000000..f44ccd6
--- /dev/null
+++ b/app/src/main/java/com/d3coding/gmusicapi/Config.java
@@ -0,0 +1,9 @@
+package com.d3coding.gmusicapi;
+
+public class Config {
+
+ static final int LOGIN_ACTIVITY = 11;
+ static final int MAX_DOWNLOADS = 25;
+ static final int SIMULTANEOUS_DOWNLOAD = 5;
+
+}
diff --git a/app/src/main/java/com/d3coding/gmusicapi/GMusicDB.java b/app/src/main/java/com/d3coding/gmusicapi/GMusicDB.java
index 9c274ec..2fc184f 100644
--- a/app/src/main/java/com/d3coding/gmusicapi/GMusicDB.java
+++ b/app/src/main/java/com/d3coding/gmusicapi/GMusicDB.java
@@ -47,16 +47,13 @@ public GMusicDB(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
- static int getDatabaseVersion() {
- return DATABASE_VERSION;
- }
-
public void onCreate(SQLiteDatabase db) {
db.execSQL(SQL_CREATE_TABLE_TRACKS);
db.execSQL(SQL_CREATE_TABLE_DOWNLOAD);
}
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
+ // TODO: updateDB
db.execSQL(SQL_DELETE_POSTS + TABLE_TRACKS);
db.execSQL(SQL_DELETE_POSTS + TABLE_DOWNLOAD);
onCreate(db);
diff --git a/app/src/main/java/com/d3coding/gmusicapi/HomeActivity.java b/app/src/main/java/com/d3coding/gmusicapi/HomeActivity.java
index 6191a8d..870ab61 100644
--- a/app/src/main/java/com/d3coding/gmusicapi/HomeActivity.java
+++ b/app/src/main/java/com/d3coding/gmusicapi/HomeActivity.java
@@ -27,14 +27,8 @@
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.navigation.NavigationView;
-
public class HomeActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
- static final int LOGIN_ACTIVITY = 11;
-
- private static final int MAX_DOWNLOADS = 25;
-
- private boolean mState = false;
private DrawerLayout drawer;
private NavigationView navigationView;
@@ -42,6 +36,8 @@ public class HomeActivity extends AppCompatActivity implements NavigationView.On
private FloatingActionButton fab;
SearchView searchView;
+ MenuItem refreshLogItem;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -57,19 +53,12 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.ac_home);
toolbar = findViewById(R.id.toolbar);
-
drawer = findViewById(R.id.drawer_layout);
navigationView = findViewById(R.id.nav_view);
+ fab = findViewById(R.id.filter_button);
setSupportActionBar(toolbar);
- fab = findViewById(R.id.filter_button);
- fab.setOnClickListener((v) -> {
- HomeFragment homeFragment = (HomeFragment) getFragment(fragment.HOME);
- if (homeFragment != null)
- homeFragment.showFilter();
- });
-
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
@@ -77,26 +66,48 @@ protected void onCreate(Bundle savedInstanceState) {
if (!mPresets.contains(getString(R.string.last_update)))
refreshDB();
- else if (mPresets.getInt(getString(R.string.database_version), 0) != GMusicDB.getDatabaseVersion()) {
- refreshDB();
- mPresets.edit().putInt(getString(R.string.database_version), GMusicDB.getDatabaseVersion()).apply();
- }
-
- swapFragment(fragment.HOME);
+ swapAndSetupFragment(new HomeFragment());
} else
- startActivityForResult(new Intent(this, LoginActivity.class), LOGIN_ACTIVITY);
+ startActivityForResult(new Intent(this, LoginActivity.class), Config.LOGIN_ACTIVITY);
}
+ void swapAndSetupFragment(Fragment fragment) {
+ getSupportFragmentManager().beginTransaction().replace(R.id.fragment_content, fragment).commit();
+ getSupportFragmentManager().executePendingTransactions();
+
+ if (fragment.getClass() == HomeFragment.class) {
+ fab.setOnClickListener((v) -> ((HomeFragment) fragment).showFilter());
+
+ ((HomeFragment) fragment).addOnScrollListener(new RecyclerView.OnScrollListener() {
+ @Override
+ public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
+ super.onScrollStateChanged(recyclerView, newState);
+ if (!recyclerView.canScrollVertically(1))
+ fab.hide();
+ else if (!fab.isExpanded()) {
+ fab.show();
+ fab.setCompatElevation(10);
+ }
+ }
+ });
+
+ } else if (fragment.getClass() == PlaylistFragment.class) {
+ fab.setOnClickListener(null);
+ }
+
+ // TODO: reInflateOptionsMenuAccordingToFragment
+ }
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
- menu.findItem(R.id.act_icon_refresh_log).setVisible(mState);
MenuItem menuItem = menu.findItem(R.id.act_icon_search);
+ refreshLogItem = menu.findItem(R.id.act_icon_refresh_log);
menuItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
@Override
@@ -116,7 +127,7 @@ public boolean onMenuItemActionCollapse(MenuItem item) {
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
- HomeFragment homeFragment = (HomeFragment) getFragment(fragment.HOME);
+ HomeFragment homeFragment = (HomeFragment) getFragment(HomeFragment.class);
if (homeFragment != null)
homeFragment.filter(query);
return false;
@@ -124,7 +135,7 @@ public boolean onQueryTextSubmit(String query) {
@Override
public boolean onQueryTextChange(String newText) {
- HomeFragment homeFragment = (HomeFragment) getFragment(fragment.HOME);
+ HomeFragment homeFragment = (HomeFragment) getFragment(HomeFragment.class);
if (homeFragment != null)
homeFragment.filter(newText);
return false;
@@ -132,9 +143,7 @@ public boolean onQueryTextChange(String newText) {
});
searchView.findViewById(androidx.appcompat.R.id.search_plate).setBackgroundColor(Color.TRANSPARENT);
-
- EditText searchEditText = searchView.findViewById(androidx.appcompat.R.id.search_src_text);
- searchEditText.setHintTextColor(Color.GRAY);
+ ((EditText) searchView.findViewById(androidx.appcompat.R.id.search_src_text)).setHintTextColor(Color.GRAY);
return true;
}
@@ -153,83 +162,39 @@ public void onBackPressed() {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.act_icon_refresh_log) {
- mState = false;
- supportInvalidateOptionsMenu();
+ refreshLogItem.setVisible(false);
return true;
} else if (id == R.id.action_download_list) {
- HomeFragment homeFragment = (HomeFragment) getFragment(fragment.HOME);
+ HomeFragment homeFragment = (HomeFragment) getFragment(HomeFragment.class);
if (homeFragment != null)
- if (homeFragment.getNumItems() <= MAX_DOWNLOADS)
- new AlertDialog.Builder(this, R.style.AppTheme_AlertDialog).setPositiveButton("Download!", (DialogInterface dialog, int which) -> {
- homeFragment.downloadFilter();
- }).setTitle("Caution!").setMessage("By clicking download you will init a thread for every music in the screen, this can take some space and last longer...").setCancelable(true).create().show();
+ if (homeFragment.getNumItems() <= Config.MAX_DOWNLOADS)
+ new AlertDialog.Builder(this, R.style.AppTheme_AlertDialog).setPositiveButton("Download!", (DialogInterface dialog, int which) -> homeFragment.downloadFilter()).setTitle("Caution!")
+ .setMessage("By clicking download you will init a thread for every music in the screen, this can take some space and last longer...").setCancelable(true).create().show();
else
- new AlertDialog.Builder(this, R.style.AppTheme_AlertDialog).setTitle("Too many musics!").setMessage("You can filter to get a minor number...").setCancelable(true).create().show();
+ new AlertDialog.Builder(this, R.style.AppTheme_AlertDialog).setTitle("Too many musics!").setMessage("You can filter to get a minor number...")
+ .setPositiveButton("ok", null).create().show();
} else if (id == R.id.action_clean_db) {
deleteDatabase(GMusicDB.DATABASE_NAME);
- swapFragment(fragment.HOME);
+ swapAndSetupFragment(new HomeFragment());
return true;
} else if (id == R.id.action_refresh_db) {
- mState = true;
- supportInvalidateOptionsMenu();
+ refreshLogItem.setVisible(true);
refreshDB();
return true;
- } else if (id == R.id.action_recreate) {
- swapFragment(fragment.HOME);
- } else if (id == R.id.action_logout) {
- this.getSharedPreferences(getString(R.string.preferences_user), Context.MODE_PRIVATE).edit().remove(getString(R.string.token)).remove(getString(R.string.last_update)).apply();
- deleteDatabase(GMusicDB.DATABASE_NAME);
- swapFragment(fragment.HOME);
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
-
- private void swapFragment(fragment mFragment) {
- if (mFragment == fragment.PLAYLIST) {
- getSupportFragmentManager().beginTransaction().replace(R.id.fragment_content, new PlaylistFragment()).commit();
- } else {
- getSupportFragmentManager().beginTransaction().replace(R.id.fragment_content, new HomeFragment()).commit();
- getSupportFragmentManager().executePendingTransactions();
-
- HomeFragment homeFragment = (HomeFragment) getFragment(fragment.HOME);
- if (homeFragment != null) {
- homeFragment.setOnReachListEndListener(new HomeFragment.OnReachListEndListener() {
- @Override
- public void OnReachListEnd(RecyclerView recyclerView) {
- if (fab != null) {
- recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
- @Override
- public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
- super.onScrollStateChanged(recyclerView, newState);
- if (!recyclerView.canScrollVertically(1))
- fab.hide();
- else if (!fab.isExpanded()) {
- fab.show();
- fab.setCompatElevation(10);
- }
- }
- });
- }
- }
- });
- }
-
- }
+ } else if (id == R.id.action_recreate)
+ swapAndSetupFragment(new HomeFragment());
+ return super.onOptionsItemSelected(item);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
- if (requestCode == LOGIN_ACTIVITY) {
+ if (requestCode == Config.LOGIN_ACTIVITY) {
if (resultCode == RESULT_OK) {
(getSharedPreferences(getString(R.string.preferences_user), Context.MODE_PRIVATE).edit()).putString(getString(R.string.token), data.getStringExtra(getString(R.string.token))).apply();
recreate();
@@ -246,11 +211,11 @@ private void refreshDB() {
new GMusicNet(this).execute(mPresets.getString(getString(R.string.token), ""));
}
- private Fragment getFragment(fragment mFragment) {
+ private Fragment getFragment(Class mClass) {
Fragment myFragment = getSupportFragmentManager().findFragmentById(R.id.fragment_content);
- if (mFragment == fragment.HOME && myFragment.getClass().getName() == HomeFragment.class.getName()) {
+ if (mClass == HomeFragment.class && myFragment.getClass() == HomeFragment.class) {
return myFragment;
- } else if (mFragment == fragment.PLAYLIST && myFragment.getClass().getName() == PlaylistFragment.class.getName()) {
+ } else if (mClass == PlaylistFragment.class && myFragment.getClass() == PlaylistFragment.class) {
return myFragment;
} else
return null;
@@ -261,27 +226,24 @@ public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
// Handle navigation view item clicks here.
int id = menuItem.getItemId();
- if (id == R.id.nav_all) {
- swapFragment(fragment.HOME);
- } else if (id == R.id.nav_playlist) {
- swapFragment(fragment.PLAYLIST);
- } else if (id == R.id.nav_settings) {
- // TODO: SettingsActivity
+ if (id == R.id.nav_all)
+ swapAndSetupFragment(new HomeFragment());
+ else if (id == R.id.nav_playlist)
+ swapAndSetupFragment(new PlaylistFragment());
+ else if (id == R.id.nav_settings)
Toast.makeText(this, getString(R.string.null_description), Toast.LENGTH_SHORT).show();
- } else if (id == R.id.nav_log) {
- // TODO: LogActivity
+ else if (id == R.id.nav_log)
Toast.makeText(this, getString(R.string.null_description), Toast.LENGTH_SHORT).show();
- } else if (id == R.id.nav_info) {
- // TODO: InfoActivity
+ else if (id == R.id.nav_info)
Toast.makeText(this, getString(R.string.null_description), Toast.LENGTH_SHORT).show();
+ else if (id == R.id.nav_logout) {
+ this.getSharedPreferences(getString(R.string.preferences_user), Context.MODE_PRIVATE).edit().remove(getString(R.string.token)).remove(getString(R.string.last_update)).apply();
+ deleteDatabase(GMusicDB.DATABASE_NAME);
+ recreate();
}
-
drawer.closeDrawer(GravityCompat.START);
return true;
}
- private enum fragment {
- HOME, PLAYLIST
- }
}
diff --git a/app/src/main/java/com/d3coding/gmusicapi/HomeFragment.java b/app/src/main/java/com/d3coding/gmusicapi/HomeFragment.java
index eae85ec..8ba10c5 100644
--- a/app/src/main/java/com/d3coding/gmusicapi/HomeFragment.java
+++ b/app/src/main/java/com/d3coding/gmusicapi/HomeFragment.java
@@ -44,8 +44,6 @@
public class HomeFragment extends Fragment {
- private static final int DOWNLOADS_NUM = 5;
-
private GMusicDB db;
private int sort = 0;
@@ -62,11 +60,14 @@ public class HomeFragment extends Fragment {
private GMusicFile gmusicFile;
- public OnReachListEndListener onReachListEndListener;
+ private RecyclerView.OnScrollListener mOnScrollListener;
+
private ThreadPoolExecutor downloadQueueService;
- void setOnReachListEndListener(OnReachListEndListener mOnReachListEndListener) {
- this.onReachListEndListener = mOnReachListEndListener;
+ void addOnScrollListener(RecyclerView.OnScrollListener mOnScrollListener) {
+ this.mOnScrollListener = mOnScrollListener;
+ if (recyclerView != null)
+ recyclerView.addOnScrollListener(mOnScrollListener);
}
@Override
@@ -83,7 +84,8 @@ public void onViewCreated(@NonNull View layoutView, @Nullable Bundle savedInstan
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(mAdapter);
- this.onReachListEndListener.OnReachListEnd(recyclerView);
+ if (mOnScrollListener != null)
+ recyclerView.addOnScrollListener(mOnScrollListener);
updateList();
@@ -182,7 +184,7 @@ public void onViewCreated(@NonNull View layoutView, @Nullable Bundle savedInstan
if (progress.doing == GMusicFile.Doing.completed)
exec.shutdown();
- }, 100, 100, TimeUnit.MILLISECONDS);
+ }, 0, 1, TimeUnit.MILLISECONDS);
builder.setOnCancelListener((dialog) -> exec.shutdown());
}
@@ -218,7 +220,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
void initThreads() {
if (downloadQueueService == null)
- downloadQueueService = (ThreadPoolExecutor) Executors.newFixedThreadPool(DOWNLOADS_NUM);
+ downloadQueueService = (ThreadPoolExecutor) Executors.newFixedThreadPool(Config.SIMULTANEOUS_DOWNLOAD);
}
void downloadFilter() {
@@ -260,9 +262,6 @@ void filter(String filterText) {
updateList();
}
- public interface OnReachListEndListener {
- void OnReachListEnd(RecyclerView recyclerView);
- }
void updateList() {
if (db == null)
@@ -271,6 +270,8 @@ void updateList() {
ConvertList.clear();
ConvertList.addAll(db.getMusicItems(sort, sortOnline, filterText, desc));
mAdapter.notifyDataSetChanged();
+
+ recyclerView.startLayoutAnimation();
}
}
diff --git a/app/src/main/java/com/d3coding/gmusicapi/LoginActivity.java b/app/src/main/java/com/d3coding/gmusicapi/LoginActivity.java
index efdad97..8135628 100644
--- a/app/src/main/java/com/d3coding/gmusicapi/LoginActivity.java
+++ b/app/src/main/java/com/d3coding/gmusicapi/LoginActivity.java
@@ -119,7 +119,7 @@ public void onCreate(Bundle savedInstanceState) {
private void loginSuccessful(String stringRet) {
Intent returnData = new Intent();
returnData.putExtra(getString(R.string.token), stringRet);
- setResult(HomeActivity.LOGIN_ACTIVITY);
+ setResult(Config.LOGIN_ACTIVITY);
setResult(RESULT_OK, returnData);
finish();
}
diff --git a/app/src/main/java/com/d3coding/gmusicapi/items/MusicAdapter.java b/app/src/main/java/com/d3coding/gmusicapi/items/MusicAdapter.java
index ea207e2..4fa00d1 100644
--- a/app/src/main/java/com/d3coding/gmusicapi/items/MusicAdapter.java
+++ b/app/src/main/java/com/d3coding/gmusicapi/items/MusicAdapter.java
@@ -34,7 +34,6 @@ public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new MyViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.rec_music_item, parent, false));
}
- // Define the method that allows the parent activity or fragment to define the listener
public void setOnItemClickListener(OnItemClickListener listener) {
this.clickListener = listener;
}
@@ -76,7 +75,6 @@ public int getItemCount() {
return convertList.size();
}
- // Define the listener interface
public interface OnItemClickListener {
void onItemClick(View itemView, int position);
}
diff --git a/app/src/main/res/layout/ac_home.xml b/app/src/main/res/layout/ac_home.xml
index a6c562f..077338f 100644
--- a/app/src/main/res/layout/ac_home.xml
+++ b/app/src/main/res/layout/ac_home.xml
@@ -66,7 +66,8 @@
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
+ android:theme="@style/ThemeOverlay.AppCompat.Light"
app:headerLayout="@layout/nav_header"
- app:menu="@menu/menu_nav_drawer" />
+ app:menu="@menu/menu_nav" />
diff --git a/app/src/main/res/layout/nav_header.xml b/app/src/main/res/layout/nav_header.xml
index 4c3439a..e4e176d 100644
--- a/app/src/main/res/layout/nav_header.xml
+++ b/app/src/main/res/layout/nav_header.xml
@@ -10,7 +10,7 @@
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
- android:theme="@style/ThemeOverlay.AppCompat.Dark">
+ android:theme="@style/ThemeOverlay.AppCompat.Light">
-
-
-
diff --git a/app/src/main/res/menu/menu_nav_drawer.xml b/app/src/main/res/menu/menu_nav.xml
similarity index 87%
rename from app/src/main/res/menu/menu_nav_drawer.xml
rename to app/src/main/res/menu/menu_nav.xml
index fcf6a74..af0d5bd 100644
--- a/app/src/main/res/menu/menu_nav_drawer.xml
+++ b/app/src/main/res/menu/menu_nav.xml
@@ -28,6 +28,10 @@
android:id="@+id/nav_info"
android:icon="@drawable/ic_menu_manage"
android:title="@string/nav_info" />
+
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 5ffc7fc..7c0401f 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -49,6 +49,7 @@
Main
Other
Log
+ Logout
Info
Title
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
index 9c31069..af5176d 100644
--- a/app/src/main/res/values/styles.xml
+++ b/app/src/main/res/values/styles.xml
@@ -8,26 +8,22 @@
- @android:color/black
-
-
-