diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..681f41a --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,116 @@ + + + + + + + +
+ + + + xmlns:android + + ^$ + + + +
+
+ + + + xmlns:.* + + ^$ + + + BY_NAME + +
+
+ + + + .*:id + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:name + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + name + + ^$ + + + +
+
+ + + + style + + ^$ + + + +
+
+ + + + .* + + ^$ + + + BY_NAME + +
+
+ + + + .* + + http://schemas.android.com/apk/res/android + + + ANDROID_ATTRIBUTE_ORDER + +
+
+ + + + .* + + .* + + + BY_NAME + +
+
+
+
+
+
\ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index d0dc175..cd02d8a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,8 +6,8 @@ android { applicationId "com.d3coding.gmusicapi" minSdkVersion 28 targetSdkVersion 28 - versionCode 21 - versionName "0.21" + versionCode 23 + versionName "0.21.2" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { diff --git a/app/src/main/java/com/d3coding/gmusicapi/GMusicDB.java b/app/src/main/java/com/d3coding/gmusicapi/GMusicDB.java index fdad823..cdd55f6 100644 --- a/app/src/main/java/com/d3coding/gmusicapi/GMusicDB.java +++ b/app/src/main/java/com/d3coding/gmusicapi/GMusicDB.java @@ -176,11 +176,11 @@ List getMusicItems(int order, int sortOnline, String filterTitle, boo if (order == 1) orderBy = column.artist.name(); else if (order == 2) - orderBy = column.artist.name(); + orderBy = column.album.name(); else if (order == 3) - orderBy = column.artist.name(); + orderBy = column.genre.name(); else - orderBy = column.artist.name(); + orderBy = column.title.name(); if (desc) orderBy += " DESC"; @@ -207,7 +207,7 @@ else if (order == 3) return ret; } - void insertUUIDbyDownloads(String uuid) { + public void insertUUIDbyDownloads(String uuid) { ContentValues contentValues = new ContentValues(); contentValues.put(downloadsColumn.uuid.name(), uuid); diff --git a/app/src/main/java/com/d3coding/gmusicapi/GMusicFile.java b/app/src/main/java/com/d3coding/gmusicapi/GMusicFile.java index 4858b59..104b11e 100644 --- a/app/src/main/java/com/d3coding/gmusicapi/GMusicFile.java +++ b/app/src/main/java/com/d3coding/gmusicapi/GMusicFile.java @@ -97,7 +97,7 @@ int getQueue(String uuid) { } } - private boolean scan(String uuid) { + public boolean scan(String uuid) { return new File(FILE_PATCH + uuid + ".mp3").exists(); } @@ -140,7 +140,7 @@ public Bitmap getBitmapThumbImage(String uuid) { public Bitmap getThumbBitmap(String uuid) { File thumbFile = new File(getPathJPG(uuid)); if (thumbFile.exists()) - return BitmapFactory.decodeFile(thumbFile.getAbsolutePath()); + return Bitmap.createScaledBitmap(BitmapFactory.decodeFile(thumbFile.getAbsolutePath()), 200, 200, false); else { String albumArtUrl = db.selectColumnByUUID(uuid, GMusicDB.column.albumArtUrl); if (!albumArtUrl.equals("")) @@ -149,7 +149,7 @@ public Bitmap getThumbBitmap(String uuid) { if (!thumbFile.exists()) { Files.copy(url.openStream(), Paths.get(thumbFile.getAbsolutePath()), StandardCopyOption.REPLACE_EXISTING); - return BitmapFactory.decodeFile(thumbFile.getAbsolutePath()); + return Bitmap.createScaledBitmap(BitmapFactory.decodeFile(thumbFile.getAbsolutePath()), 200, 200, false); } } catch (MalformedURLException e) { diff --git a/app/src/main/java/com/d3coding/gmusicapi/HomeActivity.java b/app/src/main/java/com/d3coding/gmusicapi/HomeActivity.java index c77b094..209a76b 100644 --- a/app/src/main/java/com/d3coding/gmusicapi/HomeActivity.java +++ b/app/src/main/java/com/d3coding/gmusicapi/HomeActivity.java @@ -66,8 +66,6 @@ protected void onCreate(Bundle savedInstanceState) { toggle.syncState(); navigationView.setNavigationItemSelectedListener(this); - getSupportFragmentManager().beginTransaction().add(R.id.fragment_content, new HomeFragment()).commit(); - if (!mPresets.contains(getString(R.string.last_update))) refreshDB(); else if (mPresets.getInt(getString(R.string.database_version), 0) != GMusicDB.getDatabaseVersion()) { @@ -75,6 +73,8 @@ else if (mPresets.getInt(getString(R.string.database_version), 0) != GMusicDB.ge mPresets.edit().putInt(getString(R.string.database_version), GMusicDB.getDatabaseVersion()).apply(); } + getSupportFragmentManager().beginTransaction().add(R.id.fragment_content, new HomeFragment(fab)).commit(); + } else startActivityForResult(new Intent(this, LoginActivity.class), LOGIN_ACTIVITY); @@ -160,8 +160,7 @@ public boolean onOptionsItemSelected(MenuItem item) { } else if (id == R.id.action_recreate) { getSupportFragmentManager().beginTransaction().replace(R.id.fragment_content, new HomeFragment()).commit(); } 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(); + 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); getSupportFragmentManager().beginTransaction().replace(R.id.fragment_content, new HomeFragment()).commit(); return true; @@ -174,9 +173,8 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == 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(); - getSupportFragmentManager().beginTransaction().replace(R.id.fragment_content, new HomeFragment()).commit(); + (getSharedPreferences(getString(R.string.preferences_user), Context.MODE_PRIVATE).edit()).putString(getString(R.string.token), data.getStringExtra(getString(R.string.token))).apply(); + recreate(); } else if (resultCode == RESULT_CANCELED) finish(); diff --git a/app/src/main/java/com/d3coding/gmusicapi/HomeFragment.java b/app/src/main/java/com/d3coding/gmusicapi/HomeFragment.java index 2f16498..6887391 100644 --- a/app/src/main/java/com/d3coding/gmusicapi/HomeFragment.java +++ b/app/src/main/java/com/d3coding/gmusicapi/HomeFragment.java @@ -8,6 +8,7 @@ import android.net.Uri; import android.os.Bundle; import android.os.Environment; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -32,6 +33,7 @@ import com.d3coding.gmusicapi.items.MusicAdapter; import com.d3coding.gmusicapi.items.MusicItem; +import com.google.android.material.floatingactionbutton.FloatingActionButton; import java.io.File; import java.util.ArrayList; @@ -63,6 +65,15 @@ public class HomeFragment extends Fragment { private ExecutorService downloadQueueService; private Download downloadQueue; + private FloatingActionButton floatingActionButton; + + HomeFragment() { + } + + HomeFragment(FloatingActionButton fab) { + floatingActionButton = fab; + } + @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { @@ -83,10 +94,37 @@ public void onViewCreated(@NonNull View layoutView, @Nullable Bundle savedInstan recyclerView.setItemAnimator(new DefaultItemAnimator()); recyclerView.setAdapter(mAdapter); - // TODO: scanFilesAndUpdateDB + if (floatingActionButton != null) { + recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrollStateChanged(RecyclerView recyclerView, int newState) { + super.onScrollStateChanged(recyclerView, newState); + if (!recyclerView.canScrollVertically(1)) + floatingActionButton.hide(); + else if (!floatingActionButton.isExpanded()) { + floatingActionButton.show(); + floatingActionButton.setCompatElevation(10); + } + } + }); + } updateList(); + new Thread(() -> { + Log.i("Checkup", "Started"); + List online = new ArrayList<>(); + for (MusicItem x : ConvertList) + if (gmusicFile.scan(x.getUUID())) + db.insertUUIDbyDownloads(x.getUUID()); + else + online.add(x.getUUID()); + + // TODO: removeOnlineUUIDFromDB + Log.i("Checkup", "Finished"); + }).start(); + + mAdapter.setOnItemClickListener((view, position) -> { Bitmap bitmap = gmusicFile.getBitmapThumbImage(ConvertList.get(position).getUUID());