Code cleaning

This commit is contained in:
Thomas 2020-10-14 10:31:02 +02:00
parent 3e5cefbf24
commit ca69a6e86d
12 changed files with 210 additions and 233 deletions

View File

@ -74,31 +74,26 @@ public class MainActivity extends AppCompatActivity {
private DisplayVideosFragment recentFragment, locaFragment, trendingFragment, subscriptionFragment, mostLikedFragment; private DisplayVideosFragment recentFragment, locaFragment, trendingFragment, subscriptionFragment, mostLikedFragment;
private DisplayOverviewFragment overviewFragment; private DisplayOverviewFragment overviewFragment;
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener private final BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= item -> { = item -> {
DisplayVideosFragment displayVideosFragment = null; DisplayVideosFragment displayVideosFragment = null;
switch (item.getItemId()) { int itemId = item.getItemId();
case R.id.navigation_subscription: if (itemId == R.id.navigation_subscription) {
displayVideosFragment = subscriptionFragment; displayVideosFragment = subscriptionFragment;
setTitle(R.string.subscriptions); setTitle(R.string.subscriptions);
break; } else if (itemId == R.id.navigation_trending) {
case R.id.navigation_trending:
setTitle(R.string.title_trending); setTitle(R.string.title_trending);
displayVideosFragment = trendingFragment; displayVideosFragment = trendingFragment;
break; } else if (itemId == R.id.navigation_most_liked) {
case R.id.navigation_most_liked:
setTitle(R.string.title_most_liked); setTitle(R.string.title_most_liked);
displayVideosFragment = mostLikedFragment; displayVideosFragment = mostLikedFragment;
break; } else if (itemId == R.id.navigation_recently_added) {
case R.id.navigation_recently_added:
setTitle(R.string.title_recently_added); setTitle(R.string.title_recently_added);
displayVideosFragment = recentFragment; displayVideosFragment = recentFragment;
break; } else if (itemId == R.id.navigation_local) {
case R.id.navigation_local:
setTitle(R.string.title_local); setTitle(R.string.title_local);
displayVideosFragment = locaFragment; displayVideosFragment = locaFragment;
break; } else if (itemId == R.id.navigation_discover) {
case R.id.navigation_discover:
setTitle(R.string.title_discover); setTitle(R.string.title_discover);
fm.beginTransaction().hide(active).show(overviewFragment).commit(); fm.beginTransaction().hide(active).show(overviewFragment).commit();
active = overviewFragment; active = overviewFragment;

View File

@ -674,8 +674,8 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
popup.getMenu().findItem(R.id.action_captions).setEnabled(false); popup.getMenu().findItem(R.id.action_captions).setEnabled(false);
} }
popup.setOnMenuItemClickListener(item -> { popup.setOnMenuItemClickListener(item -> {
switch (item.getItemId()) { int itemId = item.getItemId();
case R.id.action_download: if (itemId == R.id.action_download) {
if (Build.VERSION.SDK_INT >= 23) { if (Build.VERSION.SDK_INT >= 23) {
if (ContextCompat.checkSelfPermission(PeertubeActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(PeertubeActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { if (ContextCompat.checkSelfPermission(PeertubeActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(PeertubeActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(PeertubeActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, Helper.EXTERNAL_STORAGE_REQUEST_CODE); ActivityCompat.requestPermissions(PeertubeActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, Helper.EXTERNAL_STORAGE_REQUEST_CODE);
@ -685,8 +685,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
} else { } else {
Helper.manageDownloads(PeertubeActivity.this, peertube.getFileDownloadUrl(null)); Helper.manageDownloads(PeertubeActivity.this, peertube.getFileDownloadUrl(null));
} }
break; } else if (itemId == R.id.action_share) {
case R.id.action_share:
Intent sendIntent = new Intent(Intent.ACTION_SEND); Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.shared_via)); sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.shared_via));
String url; String url;
@ -699,10 +698,14 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
extra_text += "\r\n\r\n" + peertube.getName(); extra_text += "\r\n\r\n" + peertube.getName();
extra_text += "\n\n\uD83D\uDD17 " + url + "\r\n-\n"; extra_text += "\n\n\uD83D\uDD17 " + url + "\r\n-\n";
final String contentToot; final String contentToot;
if (peertube.getDescription() != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
contentToot = Html.fromHtml(peertube.getDescription(), Html.FROM_HTML_MODE_LEGACY).toString(); contentToot = Html.fromHtml(peertube.getDescription(), Html.FROM_HTML_MODE_LEGACY).toString();
else else
contentToot = Html.fromHtml(peertube.getDescription()).toString(); contentToot = Html.fromHtml(peertube.getDescription()).toString();
} else {
contentToot = "";
}
extra_text += contentToot; extra_text += contentToot;
} else { } else {
extra_text = url; extra_text = url;
@ -710,8 +713,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
sendIntent.putExtra(Intent.EXTRA_TEXT, extra_text); sendIntent.putExtra(Intent.EXTRA_TEXT, extra_text);
sendIntent.setType("text/plain"); sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, getString(R.string.share_with))); startActivity(Intent.createChooser(sendIntent, getString(R.string.share_with)));
break; } else if (itemId == R.id.action_captions) {
case R.id.action_captions:
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(PeertubeActivity.this); AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(PeertubeActivity.this);
if (captions == null) { if (captions == null) {
return true; return true;
@ -734,9 +736,9 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
Uri uri = null; Uri uri = null;
if (which > 0) { if (which > 0) {
if( !sepiaSearch) { if (!sepiaSearch) {
uri = Uri.parse("https://" + getLiveInstance(PeertubeActivity.this) + captions.get(which - 1).getCaptionPath()); uri = Uri.parse("https://" + getLiveInstance(PeertubeActivity.this) + captions.get(which - 1).getCaptionPath());
}else{ } else {
uri = Uri.parse("https://" + peertubeInstance + captions.get(which - 1).getCaptionPath()); uri = Uri.parse("https://" + peertubeInstance + captions.get(which - 1).getCaptionPath());
} }
} }
@ -796,14 +798,13 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}); });
dialogBuilder.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss()); dialogBuilder.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss());
androidx.appcompat.app.AlertDialog alertDialog = dialogBuilder.create(); AlertDialog alertDialog = dialogBuilder.create();
alertDialog.setTitle(getString(R.string.pickup_captions)); alertDialog.setTitle(getString(R.string.pickup_captions));
alertDialog.show(); alertDialog.show();
} else if (itemId == R.id.action_report) {
break; AlertDialog alertDialog;
AlertDialog.Builder dialogBuilder;
case R.id.action_report: dialogBuilder = new AlertDialog.Builder(PeertubeActivity.this);
dialogBuilder = new androidx.appcompat.app.AlertDialog.Builder(PeertubeActivity.this);
LayoutInflater inflater1 = getLayoutInflater(); LayoutInflater inflater1 = getLayoutInflater();
View dialogView = inflater1.inflate(R.layout.popup_report_choice, new LinearLayout(PeertubeActivity.this), false); View dialogView = inflater1.inflate(R.layout.popup_report_choice, new LinearLayout(PeertubeActivity.this), false);
dialogBuilder.setView(dialogView); dialogBuilder.setView(dialogView);
@ -814,7 +815,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
alertDialog.show(); alertDialog.show();
report_video.setOnClickListener(v -> reportAlert(REPORT_VIDEO, alertDialog)); report_video.setOnClickListener(v -> reportAlert(REPORT_VIDEO, alertDialog));
report_account.setOnClickListener(v -> reportAlert(REPORT_ACCOUNT, alertDialog)); report_account.setOnClickListener(v -> reportAlert(REPORT_ACCOUNT, alertDialog));
break;
} }
return true; return true;
}); });

View File

@ -87,44 +87,36 @@ public class SepiaSearchActivity extends AppCompatActivity {
}); });
RadioGroup sepia_element_nsfw = findViewById(R.id.sepia_element_nsfw); RadioGroup sepia_element_nsfw = findViewById(R.id.sepia_element_nsfw);
sepia_element_nsfw.setOnCheckedChangeListener((group, checkedId) -> { sepia_element_nsfw.setOnCheckedChangeListener((group, checkedId) -> sepiaSearchVideo.setNsfw(checkedId != R.id.sepia_element_nsfw_no));
if (checkedId == R.id.sepia_element_nsfw_no) {
sepiaSearchVideo.setNsfw(false);
} else {
sepiaSearchVideo.setNsfw(true);
}
});
RadioGroup radio_date = findViewById(R.id.radio_date); RadioGroup radio_date = findViewById(R.id.radio_date);
radio_date.setOnCheckedChangeListener((group, checkedId) -> { radio_date.setOnCheckedChangeListener((group, checkedId) -> {
switch(checkedId){ if (checkedId == R.id.sepia_element_published_date_today) {
case R.id.sepia_element_published_date_today:
Calendar cal = GregorianCalendar.getInstance(); Calendar cal = GregorianCalendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0); cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0); cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0); cal.set(Calendar.MILLISECOND, 0);
sepiaSearchVideo.setStartDate(cal.getTime()); sepiaSearchVideo.setStartDate(cal.getTime());
break; } else if (checkedId == R.id.sepia_element_published_date_last_7_days) {
case R.id.sepia_element_published_date_last_7_days: Calendar cal;
cal = GregorianCalendar.getInstance(); cal = GregorianCalendar.getInstance();
cal.setTime(new Date()); cal.setTime(new Date());
cal.add(Calendar.DAY_OF_YEAR, -7); cal.add(Calendar.DAY_OF_YEAR, -7);
sepiaSearchVideo.setStartDate(cal.getTime()); sepiaSearchVideo.setStartDate(cal.getTime());
break; } else if (checkedId == R.id.sepia_element_published_date_last_30_days) {
case R.id.sepia_element_published_date_last_30_days: Calendar cal;
cal = GregorianCalendar.getInstance(); cal = GregorianCalendar.getInstance();
cal.setTime(new Date()); cal.setTime(new Date());
cal.add(Calendar.DAY_OF_YEAR, -30); cal.add(Calendar.DAY_OF_YEAR, -30);
sepiaSearchVideo.setStartDate(cal.getTime()); sepiaSearchVideo.setStartDate(cal.getTime());
break; } else if (checkedId == R.id.sepia_element_published_date_last_365_days) {
case R.id.sepia_element_published_date_last_365_days: Calendar cal;
cal = GregorianCalendar.getInstance(); cal = GregorianCalendar.getInstance();
cal.setTime(new Date()); cal.setTime(new Date());
cal.add(Calendar.DAY_OF_YEAR, -365); cal.add(Calendar.DAY_OF_YEAR, -365);
sepiaSearchVideo.setStartDate(cal.getTime()); sepiaSearchVideo.setStartDate(cal.getTime());
break; } else {
default:
sepiaSearchVideo.setStartDate(null); sepiaSearchVideo.setStartDate(null);
} }
}); });
@ -132,23 +124,18 @@ public class SepiaSearchActivity extends AppCompatActivity {
RadioGroup duration = findViewById(R.id.duration); RadioGroup duration = findViewById(R.id.duration);
duration.setOnCheckedChangeListener((group, checkedId) -> { duration.setOnCheckedChangeListener((group, checkedId) -> {
switch(checkedId){ if (checkedId == R.id.sepia_element_duration_short) {
case R.id.sepia_element_duration_short:
sepiaSearchVideo.setDurationMin(0); sepiaSearchVideo.setDurationMin(0);
sepiaSearchVideo.setDurationMax(240); sepiaSearchVideo.setDurationMax(240);
break; } else if (checkedId == R.id.sepia_element_duration_medium) {
case R.id.sepia_element_duration_medium:
sepiaSearchVideo.setDurationMin(240); sepiaSearchVideo.setDurationMin(240);
sepiaSearchVideo.setDurationMax(600); sepiaSearchVideo.setDurationMax(600);
break; } else if (checkedId == R.id.sepia_element_duration_long) {
case R.id.sepia_element_duration_long:
sepiaSearchVideo.setDurationMin(600); sepiaSearchVideo.setDurationMin(600);
sepiaSearchVideo.setDurationMax(999999999); sepiaSearchVideo.setDurationMax(999999999);
break; } else {
default:
sepiaSearchVideo.setDurationMin(0); sepiaSearchVideo.setDurationMin(0);
sepiaSearchVideo.setDurationMax(999999999); sepiaSearchVideo.setDurationMax(999999999);
break;
} }
}); });

View File

@ -319,12 +319,11 @@ public class ShowAccountActivity extends AppCompatActivity {
account_follow.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(ShowAccountActivity.this, R.color.red_1))); account_follow.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(ShowAccountActivity.this, R.color.red_1)));
} }
doAction = action.UNFOLLOW; doAction = action.UNFOLLOW;
account_follow.setVisibility(View.VISIBLE);
} else { } else {
account_follow.setText(R.string.action_follow); account_follow.setText(R.string.action_follow);
doAction = action.FOLLOW; doAction = action.FOLLOW;
account_follow.setVisibility(View.VISIBLE);
} }
account_follow.setVisibility(View.VISIBLE);
} }

View File

@ -70,9 +70,7 @@ import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.MUTE
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.REPORT_ACCOUNT; import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.REPORT_ACCOUNT;
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.UNFOLLOW; import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.UNFOLLOW;
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.DataType.CHANNEL; import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.DataType.CHANNEL;
import static app.fedilab.fedilabtube.helper.Helper.getLiveInstance;
import static app.fedilab.fedilabtube.helper.Helper.isLoggedIn; import static app.fedilab.fedilabtube.helper.Helper.isLoggedIn;
import static app.fedilab.fedilabtube.viewmodel.TimelineVM.TimelineType.SEPIA_SEARCH;
public class ShowChannelActivity extends AppCompatActivity { public class ShowChannelActivity extends AppCompatActivity {
@ -324,12 +322,11 @@ public class ShowChannelActivity extends AppCompatActivity {
account_follow.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(ShowChannelActivity.this, R.color.red_1))); account_follow.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(ShowChannelActivity.this, R.color.red_1)));
} }
doAction = action.UNFOLLOW; doAction = action.UNFOLLOW;
account_follow.setVisibility(View.VISIBLE);
} else { } else {
account_follow.setText(R.string.action_follow); account_follow.setText(R.string.action_follow);
doAction = action.FOLLOW; doAction = action.FOLLOW;
account_follow.setVisibility(View.VISIBLE);
} }
account_follow.setVisibility(View.VISIBLE);
} }

View File

@ -129,11 +129,11 @@ public class WebviewActivity extends AppCompatActivity {
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { int itemId = item.getItemId();
case android.R.id.home: if (itemId == android.R.id.home) {
finish(); finish();
return true; return true;
case R.id.action_go: } else if (itemId == R.id.action_go) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
try { try {
startActivity(browserIntent); startActivity(browserIntent);
@ -141,9 +141,8 @@ public class WebviewActivity extends AppCompatActivity {
Toasty.error(WebviewActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show(); Toasty.error(WebviewActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
} }
return true; return true;
default:
return super.onOptionsItemSelected(item);
} }
return super.onOptionsItemSelected(item);
} }
public void setUrl(String newUrl) { public void setUrl(String newUrl) {

View File

@ -23,6 +23,8 @@ import android.widget.Button;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.MediaController; import android.widget.MediaController;
import androidx.core.content.res.ResourcesCompat;
import app.fedilab.fedilabtube.PeertubeActivity; import app.fedilab.fedilabtube.PeertubeActivity;
import app.fedilab.fedilabtube.R; import app.fedilab.fedilabtube.R;
import app.fedilab.fedilabtube.client.data.VideoData.Video; import app.fedilab.fedilabtube.client.data.VideoData.Video;
@ -36,7 +38,7 @@ public class FullScreenMediaController extends MediaController {
private ImageButton fullScreen; private ImageButton fullScreen;
private Button resolution; private Button resolution;
private Context context; private final Context context;
private Video peertube; private Video peertube;
private String resolutionVal; private String resolutionVal;
@ -85,12 +87,11 @@ public class FullScreenMediaController extends MediaController {
if (((PeertubeActivity) getContext()).getFullscreen() == fullscreen.ON) { if (((PeertubeActivity) getContext()).getFullscreen() == fullscreen.ON) {
Resources resources = getResources(); Resources resources = getResources();
fullScreen.setImageDrawable(resources.getDrawable(R.drawable.ic_baseline_fullscreen_exit_24)); fullScreen.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ic_baseline_fullscreen_exit_24, null));
} else { } else {
Resources resources = getResources(); Resources resources = getResources();
fullScreen.setImageDrawable(resources.getDrawable(R.drawable.ic_baseline_fullscreen_24)); fullScreen.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ic_baseline_fullscreen_24, null));
} }
//add listener to image button to handle full screen and exit full screen events //add listener to image button to handle full screen and exit full screen events
fullScreen.setOnClickListener(v -> { fullScreen.setOnClickListener(v -> {
@ -115,10 +116,10 @@ public class FullScreenMediaController extends MediaController {
//fullscreen indicator from intent //fullscreen indicator from intent
if (((PeertubeActivity) getContext()).getFullscreen() == fullscreen.ON) { if (((PeertubeActivity) getContext()).getFullscreen() == fullscreen.ON) {
Resources resources = getResources(); Resources resources = getResources();
fullScreen.setImageDrawable(resources.getDrawable(R.drawable.ic_baseline_fullscreen_exit_24)); fullScreen.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ic_baseline_fullscreen_exit_24, null));
} else { } else {
Resources resources = getResources(); Resources resources = getResources();
fullScreen.setImageDrawable(resources.getDrawable(R.drawable.ic_baseline_fullscreen_24)); fullScreen.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ic_baseline_fullscreen_24, null));
} }
} }

View File

@ -12,8 +12,8 @@ import app.fedilab.fedilabtube.R;
public class RoundedBackgroundSpan extends ReplacementSpan { public class RoundedBackgroundSpan extends ReplacementSpan {
private int backgroundColor; private final int backgroundColor;
private int textColor; private final int textColor;
public RoundedBackgroundSpan(Context context) { public RoundedBackgroundSpan(Context context) {
super(); super();

View File

@ -34,7 +34,7 @@ import app.fedilab.fedilabtube.helper.Helper;
public class AccountDAO { public class AccountDAO {
public Context context; public Context context;
private SQLiteDatabase db; private final SQLiteDatabase db;
public AccountDAO(Context context, SQLiteDatabase db) { public AccountDAO(Context context, SQLiteDatabase db) {

View File

@ -15,7 +15,6 @@ package app.fedilab.fedilabtube.viewmodel;
* see <http://www.gnu.org/licenses>. */ * see <http://www.gnu.org/licenses>. */
import android.app.Application; import android.app.Application;
import android.content.Context;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;

View File

@ -5,7 +5,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:4.0.2' classpath 'com.android.tools.build:gradle:4.1.0'
def nav_version = "2.3.0" def nav_version = "2.3.0"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version" classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong

View File

@ -1,6 +1,6 @@
#Thu Jun 25 14:34:43 CEST 2020 #Wed Oct 14 09:54:01 CEST 2020
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip