Skip to content

Commit

Permalink
fix bugs; clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
Albresky committed Jul 16, 2023
1 parent 63b0f23 commit ab0f6d1
Show file tree
Hide file tree
Showing 14 changed files with 231 additions and 278 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ android {
minSdk 24
targetSdk 33
versionCode 2
versionName "0.0.3"
versionName "0.0.4_final"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
24 changes: 16 additions & 8 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,31 @@
<activity
android:name=".UI.AboutActivity"
android:exported="false"
android:screenOrientation="portrait " />
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".UI.SettingsActivity"
android:exported="false"
android:screenOrientation="portrait " />
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity" />

<service
android:name=".Service.MusicService"
android:enabled="true"
android:exported="false"
android:screenOrientation="portrait " />
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity" />

<activity
android:name=".UI.MusicPlayerActivity"
android:exported="false"
android:screenOrientation="portrait " />
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".MainActivity"
android:exported="true"
android:screenOrientation="portrait ">
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand All @@ -52,15 +57,18 @@
<activity
android:name=".UI.MusicActivity"
android:exported="false"
android:screenOrientation="portrait " />
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".UI.VideoActivity"
android:exported="false"
android:screenOrientation="portrait " />
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity" />
<activity
android:name=".UI.VideoPlayerActivity"
android:exported="false"
android:screenOrientation="portrait " />
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity" />
</application>

</manifest>
10 changes: 7 additions & 3 deletions app/src/main/java/cn/albresky/splayer/Adapter/VideoAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
Expand Down Expand Up @@ -74,6 +73,12 @@ public void onBindViewHolder(@NonNull ViewHolder holder, int position) {

if (thumbnail == null) {
holder.videoWarning.setVisibility(View.VISIBLE);
holder.videoThumbnail.setScaleType(ImageView.ScaleType.FIT_CENTER);
holder.videoThumbnail.setImageResource(R.drawable.baseline_video_half);
} else {
holder.videoWarning.setVisibility(View.GONE);
holder.videoThumbnail.setScaleType(ImageView.ScaleType.CENTER_CROP);
holder.videoThumbnail.setImageBitmap(thumbnail);
}
holder.videoIndex.setText(String.valueOf(position + 1));
holder.videoName.setText(video.getName());
Expand All @@ -82,9 +87,8 @@ public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.videoResolution.setText(Converter.resolutionConvert(video.getWidth(), video.getHeight()));
holder.videoDuration.setText(duration);
holder.videoType.setText(video.getType());
holder.videoThumbnail.setImageBitmap(thumbnail);

holder.itemView.setOnClickListener(v -> {
Toast.makeText(mContext, "点击了第" + position + "项", Toast.LENGTH_SHORT).show();
onItemClickListener.onItemClick(v, position);
});
}
Expand Down
55 changes: 1 addition & 54 deletions app/src/main/java/cn/albresky/splayer/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,12 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {

@Override
protected void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "onCreate() called");
super.onCreate(savedInstanceState);
binding = ActivityMainBinding.inflate(getLayoutInflater());
View view = binding.getRoot();
setContentView(view);

// setSupportActionBar(binding.toolbar);

Log.d(TAG, "onCreate() called");


checkPermissions();

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
Expand All @@ -80,8 +76,6 @@ protected void onCreate(Bundle savedInstanceState) {
startActivity(intent);
return true;
});

// test zone end
}

private void checkPermissionsAndLaunch(@NonNull ActivityResultLauncher<Intent> launcher, @NonNull Intent intent) {
Expand Down Expand Up @@ -128,56 +122,11 @@ private void checkPermissions() {
Intent intent = new Intent(getApplicationContext(), MusicActivity.class);
checkPermissionsAndLaunch(launcher, intent);
});
// if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q) {
// if (permissionGranted[PERMISSION_READ_EXTERNAL] && permissionGranted[PERMISSION_WRITE_EXTERNAL]) {
// startActivity(new Intent(getApplicationContext(), MusicActivity.class));
// } else if (ContextCompat.checkSelfPermission(
// getApplicationContext(), android.Manifest.permission.READ_EXTERNAL_STORAGE
// ) != PackageManager.PERMISSION_GRANTED) {
// requestPermissions(new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE}, PERMISSION_READ_EXTERNAL);
// } else if (ContextCompat.checkSelfPermission(
// getApplicationContext(), android.Manifest.permission.WRITE_EXTERNAL_STORAGE
// ) != PackageManager.PERMISSION_GRANTED) {
// requestPermissions(new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSION_WRITE_EXTERNAL);
// }
// } else {
// if (!Environment.isExternalStorageManager()) {
// Toast.makeText(this, "请求所有文件访问权限", Toast.LENGTH_SHORT).show();
// Intent intent = new Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
// launcher.launch(intent);
// } else {
// Toast.makeText(this, "已获得所有文件访问权限", Toast.LENGTH_SHORT).show();
// startActivity(new Intent(getApplicationContext(), MusicActivity.class));
// }
// }

binding.btnVideo.setOnClickListener(v -> {
Intent intent = new Intent(getApplicationContext(), VideoActivity.class);
checkPermissionsAndLaunch(launcher, intent);
});

// if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q) {
// if (permissionGranted[PERMISSION_READ_EXTERNAL] && permissionGranted[PERMISSION_WRITE_EXTERNAL]) {
// startActivity(new Intent(getApplicationContext(), VideoActivity.class));
// } else if (ContextCompat.checkSelfPermission(
// getApplicationContext(), android.Manifest.permission.READ_EXTERNAL_STORAGE
// ) != PackageManager.PERMISSION_GRANTED) {
// requestPermissions(new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE}, PERMISSION_READ_EXTERNAL);
// } else if (ContextCompat.checkSelfPermission(
// getApplicationContext(), android.Manifest.permission.WRITE_EXTERNAL_STORAGE
// ) != PackageManager.PERMISSION_GRANTED) {
// requestPermissions(new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSION_WRITE_EXTERNAL);
// }
// } else {
// if (!Environment.isExternalStorageManager()) {
// Toast.makeText(this, "请求所有文件访问权限", Toast.LENGTH_SHORT).show();
// Intent intent = new Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
// launcher.launch(intent);
// } else {
// Toast.makeText(this, "已获得所有文件访问权限", Toast.LENGTH_SHORT).show();
// startActivity(new Intent(getApplicationContext(), VideoActivity.class));
// }
// }
}


Expand All @@ -204,6 +153,4 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
}
}
}


}
8 changes: 0 additions & 8 deletions app/src/main/java/cn/albresky/splayer/UI/MusicActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ private void initView() {
binding.btnPlay.setEnabled(false);
binding.btnPlay.setOnClickListener(v -> {
if (mContorller != null) {
// if (!mContorller.isPrepared()) {
// Log.d(TAG, "initView:[btn_play clicked] [isPrepared=false] => playerStart(0)");
// playerStart(0);
// } else
if (mContorller.isPlaying()) {
Log.d(TAG, "initView:[btn_play clicked] [isPlaying=true] => playerPause()");
playerPause();
Expand Down Expand Up @@ -139,8 +135,6 @@ private void initView() {
Log.d(TAG, "initView: playerSongName clicked");
startMusicPlayerActivity(mIndex);
});


}

private void getMusicList() {
Expand Down Expand Up @@ -306,6 +300,4 @@ public void onServiceDisconnected(ComponentName name) {
Log.d(TAG, "onServiceDisconnected: ");
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ protected void onCreate(Bundle savedInstanceState) {
}

private void initView() {
// binding.ivMusicCover.setImageBitmap(Converter.createBitmapWithScale(Converter.createBitmapWithNoScale(this, R.drawable.record), 512, 512, false));

String jList = (String) getIntent().getSerializableExtra("songList");
Gson gson = new Gson();
mList = gson.fromJson(jList, new TypeToken<List<Song>>() {
Expand Down Expand Up @@ -154,13 +152,6 @@ private void initView() {
binding.playNext.setOnClickListener(v -> {
Log.d(TAG, "onClick: next");
playNext();
// int nextIndex = songIndex >= mList.size() - 1 ? 0 : songIndex + 1;
// songIndex = nextIndex;
// song = mList.get(songIndex);
// mContorller.prepare(songIndex);
// mContorller.play();
// resetUI();
// startAnimation();
});

binding.playPrev.setOnClickListener(v -> {
Expand Down
20 changes: 13 additions & 7 deletions app/src/main/java/cn/albresky/splayer/UI/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ public class SettingsActivity extends AppCompatActivity {

private final String TAG = "loadSettings";
private ActivitySettingsBinding binding;

private boolean enableDeepScan = false;

private int scanDepth = 4;


Expand All @@ -34,12 +32,14 @@ protected void onCreate(Bundle savedInstanceState) {
initView();
}


@Override
protected void onDestroy() {
Log.d(TAG, "onDestroy: ");
super.onDestroy();
}


private void initView() {
Log.d(TAG, "initView: ");

Expand All @@ -54,7 +54,6 @@ private void initView() {
saveSettings();
});


binding.txtCache.setText(getTotalCacheSize());

binding.btnClearCache.setOnClickListener(v -> {
Expand All @@ -79,6 +78,7 @@ private void initView() {
});
}


private void loadSettings() {
Log.d(TAG, "loadSettings: ");
SharedPreferences sp = getSharedPreferences("settings", MODE_PRIVATE);
Expand All @@ -91,6 +91,7 @@ private void loadSettings() {
binding.deepScan.setChecked(sp.getBoolean("enableDeepScan", false));
}


private void saveSettings() {
Log.d(TAG, "saveSettings: ");
SharedPreferences sp = getSharedPreferences("settings", MODE_PRIVATE);
Expand All @@ -100,6 +101,7 @@ private void saveSettings() {
editor.apply();
}


public String getTotalCacheSize() {
long cacheSize;
try {
Expand All @@ -114,13 +116,15 @@ public String getTotalCacheSize() {
return getFormatSize(cacheSize);
}


public String getFormatSize(long size) {
long kb = size / 1024;
int m = (int) (kb / 1024);
int kbs = (int) (kb % 1024);
return m + "." + kbs + "MB";
}


public long getFolderSize(File file) throws Exception {
long size = 0;
try {
Expand All @@ -139,8 +143,8 @@ public long getFolderSize(File file) throws Exception {
return size;
}


public void clearAllCache() {
deleteDir(this.getCacheDir());
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
if (deleteDir(this.getExternalCacheDir())) {
Log.d(TAG, "clearAllCache: ");
Expand All @@ -150,19 +154,21 @@ public void clearAllCache() {
}
}


private boolean deleteDir(File dir) {
if (dir != null && dir.isDirectory()) {
String[] children = dir.list();
for (int i = 0; i < children.length; i++) {
boolean success = deleteDir(new File(dir, children[i]));
for (String child : children) {
boolean success = deleteDir(new File(dir, child));
if (!success) {
return false;
}
}
}
return dir.delete();
return dir != null && dir.delete();
}


@Override
public void finish() {
Log.d(TAG, "finish: ");
Expand Down
Loading

0 comments on commit ab0f6d1

Please sign in to comment.