Skip to content
This repository has been archived by the owner on Oct 18, 2020. It is now read-only.

Commit

Permalink
Bugs solved... (Wrong files commit)
Browse files Browse the repository at this point in the history
- filter options
- hide fab search on reach UI end
- downloaded files not in db
  • Loading branch information
mateusjdev committed Jul 12, 2019
1 parent 2ac9e40 commit dae2454
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 17 deletions.
116 changes: 116 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/com/d3coding/gmusicapi/GMusicDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ List<MusicItem> 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";
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/d3coding/gmusicapi/GMusicFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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(""))
Expand All @@ -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) {
Expand Down
12 changes: 5 additions & 7 deletions app/src/main/java/com/d3coding/gmusicapi/HomeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ 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()) {
refreshDB();
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);

Expand Down Expand Up @@ -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;
Expand All @@ -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();

Expand Down
40 changes: 39 additions & 1 deletion app/src/main/java/com/d3coding/gmusicapi/HomeFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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<String> 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());
Expand Down

0 comments on commit dae2454

Please sign in to comment.