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 DisplayOverviewFragment overviewFragment;
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
private final BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= item -> {
DisplayVideosFragment displayVideosFragment = null;
switch (item.getItemId()) {
case R.id.navigation_subscription:
int itemId = item.getItemId();
if (itemId == R.id.navigation_subscription) {
displayVideosFragment = subscriptionFragment;
setTitle(R.string.subscriptions);
break;
case R.id.navigation_trending:
} else if (itemId == R.id.navigation_trending) {
setTitle(R.string.title_trending);
displayVideosFragment = trendingFragment;
break;
case R.id.navigation_most_liked:
} else if (itemId == R.id.navigation_most_liked) {
setTitle(R.string.title_most_liked);
displayVideosFragment = mostLikedFragment;
break;
case R.id.navigation_recently_added:
} else if (itemId == R.id.navigation_recently_added) {
setTitle(R.string.title_recently_added);
displayVideosFragment = recentFragment;
break;
case R.id.navigation_local:
} else if (itemId == R.id.navigation_local) {
setTitle(R.string.title_local);
displayVideosFragment = locaFragment;
break;
case R.id.navigation_discover:
} else if (itemId == R.id.navigation_discover) {
setTitle(R.string.title_discover);
fm.beginTransaction().hide(active).show(overviewFragment).commit();
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.setOnMenuItemClickListener(item -> {
switch (item.getItemId()) {
case R.id.action_download:
int itemId = item.getItemId();
if (itemId == R.id.action_download) {
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) {
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 {
Helper.manageDownloads(PeertubeActivity.this, peertube.getFileDownloadUrl(null));
}
break;
case R.id.action_share:
} else if (itemId == R.id.action_share) {
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.shared_via));
String url;
@ -699,10 +698,14 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
extra_text += "\r\n\r\n" + peertube.getName();
extra_text += "\n\n\uD83D\uDD17 " + url + "\r\n-\n";
final String contentToot;
if (peertube.getDescription() != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
contentToot = Html.fromHtml(peertube.getDescription(), Html.FROM_HTML_MODE_LEGACY).toString();
else
contentToot = Html.fromHtml(peertube.getDescription()).toString();
} else {
contentToot = "";
}
extra_text += contentToot;
} else {
extra_text = url;
@ -710,8 +713,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
sendIntent.putExtra(Intent.EXTRA_TEXT, extra_text);
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, getString(R.string.share_with)));
break;
case R.id.action_captions:
} else if (itemId == R.id.action_captions) {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(PeertubeActivity.this);
if (captions == null) {
return true;
@ -796,14 +798,13 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
});
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.show();
break;
case R.id.action_report:
dialogBuilder = new androidx.appcompat.app.AlertDialog.Builder(PeertubeActivity.this);
} else if (itemId == R.id.action_report) {
AlertDialog alertDialog;
AlertDialog.Builder dialogBuilder;
dialogBuilder = new AlertDialog.Builder(PeertubeActivity.this);
LayoutInflater inflater1 = getLayoutInflater();
View dialogView = inflater1.inflate(R.layout.popup_report_choice, new LinearLayout(PeertubeActivity.this), false);
dialogBuilder.setView(dialogView);
@ -814,7 +815,6 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
alertDialog.show();
report_video.setOnClickListener(v -> reportAlert(REPORT_VIDEO, alertDialog));
report_account.setOnClickListener(v -> reportAlert(REPORT_ACCOUNT, alertDialog));
break;
}
return true;
});

View File

@ -87,44 +87,36 @@ public class SepiaSearchActivity extends AppCompatActivity {
});
RadioGroup sepia_element_nsfw = findViewById(R.id.sepia_element_nsfw);
sepia_element_nsfw.setOnCheckedChangeListener((group, checkedId) -> {
if (checkedId == R.id.sepia_element_nsfw_no) {
sepiaSearchVideo.setNsfw(false);
} else {
sepiaSearchVideo.setNsfw(true);
}
});
sepia_element_nsfw.setOnCheckedChangeListener((group, checkedId) -> sepiaSearchVideo.setNsfw(checkedId != R.id.sepia_element_nsfw_no));
RadioGroup radio_date = findViewById(R.id.radio_date);
radio_date.setOnCheckedChangeListener((group, checkedId) -> {
switch(checkedId){
case R.id.sepia_element_published_date_today:
if (checkedId == R.id.sepia_element_published_date_today) {
Calendar cal = GregorianCalendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
sepiaSearchVideo.setStartDate(cal.getTime());
break;
case R.id.sepia_element_published_date_last_7_days:
} else if (checkedId == R.id.sepia_element_published_date_last_7_days) {
Calendar cal;
cal = GregorianCalendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.DAY_OF_YEAR, -7);
sepiaSearchVideo.setStartDate(cal.getTime());
break;
case R.id.sepia_element_published_date_last_30_days:
} else if (checkedId == R.id.sepia_element_published_date_last_30_days) {
Calendar cal;
cal = GregorianCalendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.DAY_OF_YEAR, -30);
sepiaSearchVideo.setStartDate(cal.getTime());
break;
case R.id.sepia_element_published_date_last_365_days:
} else if (checkedId == R.id.sepia_element_published_date_last_365_days) {
Calendar cal;
cal = GregorianCalendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.DAY_OF_YEAR, -365);
sepiaSearchVideo.setStartDate(cal.getTime());
break;
default:
} else {
sepiaSearchVideo.setStartDate(null);
}
});
@ -132,23 +124,18 @@ public class SepiaSearchActivity extends AppCompatActivity {
RadioGroup duration = findViewById(R.id.duration);
duration.setOnCheckedChangeListener((group, checkedId) -> {
switch(checkedId){
case R.id.sepia_element_duration_short:
if (checkedId == R.id.sepia_element_duration_short) {
sepiaSearchVideo.setDurationMin(0);
sepiaSearchVideo.setDurationMax(240);
break;
case R.id.sepia_element_duration_medium:
} else if (checkedId == R.id.sepia_element_duration_medium) {
sepiaSearchVideo.setDurationMin(240);
sepiaSearchVideo.setDurationMax(600);
break;
case R.id.sepia_element_duration_long:
} else if (checkedId == R.id.sepia_element_duration_long) {
sepiaSearchVideo.setDurationMin(600);
sepiaSearchVideo.setDurationMax(999999999);
break;
default:
} else {
sepiaSearchVideo.setDurationMin(0);
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)));
}
doAction = action.UNFOLLOW;
account_follow.setVisibility(View.VISIBLE);
} else {
account_follow.setText(R.string.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.UNFOLLOW;
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.viewmodel.TimelineVM.TimelineType.SEPIA_SEARCH;
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)));
}
doAction = action.UNFOLLOW;
account_follow.setVisibility(View.VISIBLE);
} else {
account_follow.setText(R.string.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
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
int itemId = item.getItemId();
if (itemId == android.R.id.home) {
finish();
return true;
case R.id.action_go:
} else if (itemId == R.id.action_go) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
try {
startActivity(browserIntent);
@ -141,9 +141,8 @@ public class WebviewActivity extends AppCompatActivity {
Toasty.error(WebviewActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show();
}
return true;
default:
return super.onOptionsItemSelected(item);
}
return super.onOptionsItemSelected(item);
}
public void setUrl(String newUrl) {

View File

@ -23,6 +23,8 @@ import android.widget.Button;
import android.widget.ImageButton;
import android.widget.MediaController;
import androidx.core.content.res.ResourcesCompat;
import app.fedilab.fedilabtube.PeertubeActivity;
import app.fedilab.fedilabtube.R;
import app.fedilab.fedilabtube.client.data.VideoData.Video;
@ -36,7 +38,7 @@ public class FullScreenMediaController extends MediaController {
private ImageButton fullScreen;
private Button resolution;
private Context context;
private final Context context;
private Video peertube;
private String resolutionVal;
@ -85,12 +87,11 @@ public class FullScreenMediaController extends MediaController {
if (((PeertubeActivity) getContext()).getFullscreen() == fullscreen.ON) {
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 {
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
fullScreen.setOnClickListener(v -> {
@ -115,10 +116,10 @@ public class FullScreenMediaController extends MediaController {
//fullscreen indicator from intent
if (((PeertubeActivity) getContext()).getFullscreen() == fullscreen.ON) {
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 {
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 {
private int backgroundColor;
private int textColor;
private final int backgroundColor;
private final int textColor;
public RoundedBackgroundSpan(Context context) {
super();

View File

@ -34,7 +34,7 @@ import app.fedilab.fedilabtube.helper.Helper;
public class AccountDAO {
public Context context;
private SQLiteDatabase db;
private final 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>. */
import android.app.Application;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;

View File

@ -5,7 +5,7 @@ buildscript {
jcenter()
}
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"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
// 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
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
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