Clean code

This commit is contained in:
Thomas 2023-07-27 14:47:22 +02:00
parent 44752cc329
commit bf447d823e
27 changed files with 102 additions and 121 deletions

View File

@ -212,6 +212,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
public static String regex_home, regex_local, regex_public;
public static BaseAccount currentAccount;
public static iconLauncher mLauncher = iconLauncher.BUBBLES;
public static boolean headerMenuOpen;
Fragment currentFragment;
private AppBarConfiguration mAppBarConfiguration;
private ActivityMainBinding binding;
@ -330,7 +331,6 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
}
};
private NetworkStateReceiver networkStateReceiver;
public static boolean headerMenuOpen;
public static void fetchRecentAccounts(Activity activity, NavHeaderMainBinding headerMainBinding) {
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity);
@ -644,8 +644,6 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
popup.show();
}
protected abstract void rateThisApp();
/**
* Open notifications tab when coming from a notification device
*
@ -1034,6 +1032,8 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
intent.setFlags(0);
}
protected abstract void rateThisApp();
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);

View File

@ -404,12 +404,21 @@ public class CheckHomeCacheActivity extends BaseBarActivity {
}).start();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
public enum range {
ALL,
DAY
}
public static class GraphElement {
String dateLabel;
int count;
@ -424,15 +433,6 @@ public class CheckHomeCacheActivity extends BaseBarActivity {
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
public class CustomMarkerView extends MarkerView {
private final TextView tvContent;

View File

@ -79,34 +79,34 @@ class InstanceHealthActivity : DialogFragment() {
}
binding.name.text = instance.name
if (instance.up) {
binding.up.setText(app.fedilab.android.R.string.is_up)
binding.up.setText(R.string.is_up)
binding.up.setTextColor(
ThemeHelper.getAttColor(
requireContext(),
app.fedilab.android.R.attr.colorPrimary
R.attr.colorPrimary
)
)
} else {
binding.up.setText(app.fedilab.android.R.string.is_down)
binding.up.setText(R.string.is_down)
binding.up.setTextColor(
ThemeHelper.getAttColor(
requireContext(),
app.fedilab.android.R.attr.colorError
R.attr.colorError
)
)
}
binding.uptime.text = getString(
app.fedilab.android.R.string.instance_health_uptime,
R.string.instance_health_uptime,
instance.uptime * 100
)
if (instance.checked_at != null)
binding.checkedAt.text =
getString(
app.fedilab.android.R.string.instance_health_checkedat,
R.string.instance_health_checkedat,
Helper.dateToString(instance.checked_at)
)
binding.values.text = getString(
app.fedilab.android.R.string.instance_health_indication,
R.string.instance_health_indication,
instance.version,
Helper.withSuffix(instance.active_users.toLong()),
Helper.withSuffix(instance.statuses.toLong())

View File

@ -373,7 +373,8 @@ public class MastodonListActivity extends BaseBarActivity implements MastodonLis
Intent intentBD = new Intent(Helper.BROADCAST_DATA);
intentBD.putExtras(b);
LocalBroadcastManager.getInstance(MastodonListActivity.this).sendBroadcast(intentBD);
} catch (DBException e) {
} catch (
DBException e) {
e.printStackTrace();
}
}).start();

View File

@ -67,10 +67,10 @@ import es.dmoral.toasty.Toasty;
public class SearchResultTabActivity extends BaseBarActivity {
public Boolean tagEmpty, accountEmpty;
private String search;
private ActivitySearchResultTabsBinding binding;
private TabLayout.Tab initial;
public Boolean tagEmpty, accountEmpty;
@Override
protected void onCreate(Bundle savedInstanceState) {

View File

@ -48,16 +48,6 @@ public class LemmyPost implements Serializable {
@SerializedName("unread_comments")
public int unread_comments;
public static class LemmyPosts {
@SerializedName("posts")
public List<LemmyPost> posts;
}
public static class LemmyComments {
@SerializedName("comments")
public List<LemmyPost> comments;
}
public static Status convert(LemmyPost lemmyPost, String instance) {
Status status = new Status();
status.id = lemmyPost.comment == null ? lemmyPost.post.id : lemmyPost.comment.id;
@ -109,6 +99,16 @@ public class LemmyPost implements Serializable {
return status;
}
public static class LemmyPosts {
@SerializedName("posts")
public List<LemmyPost> posts;
}
public static class LemmyComments {
@SerializedName("comments")
public List<LemmyPost> comments;
}
public static class Post implements Serializable {
@SerializedName("id")
public String id;

View File

@ -30,8 +30,8 @@ import app.fedilab.android.mastodon.client.entities.api.Status;
public class CustomEmoji extends ReplacementSpan {
private float scale;
private final WeakReference<View> viewWeakReference;
private float scale;
private Drawable imageDrawable;
private boolean callbackCalled;

View File

@ -192,7 +192,9 @@ public class ECDHFedilab {
cipher.init(Cipher.DECRYPT_MODE, aesKey, gCMParameterSpec);
byte[] decrypted = cipher.doFinal(ciphertext);
decryptedStr = new String(decrypted, 2, decrypted.length - 2, StandardCharsets.UTF_8);
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidAlgorithmParameterException | InvalidKeyException | BadPaddingException | IllegalBlockSizeException e) {
} catch (NoSuchAlgorithmException | NoSuchPaddingException |
InvalidAlgorithmParameterException | InvalidKeyException | BadPaddingException |
IllegalBlockSizeException e) {
e.printStackTrace();
return null;
}

View File

@ -467,7 +467,6 @@ public class Helper {
}
/***
* Check if the user is connected to Internet
* @return boolean

View File

@ -133,8 +133,8 @@ import es.dmoral.toasty.Toasty;
public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final int searchDeep = 15;
public static final int TYPE_COMPOSE = 1;
private static final int searchDeep = 15;
public static boolean autocomplete = false;
public static String[] ALPHA = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r",
"s", "t", "u", "v", "w", "x", "y", "z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "!", ",", "?",
@ -985,7 +985,7 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
contentBuilder.append(subject);
}
if(contentBuilder.length() > 0) {
if (contentBuilder.length() > 0) {
contentBuilder.append("\n\n");
}

View File

@ -190,10 +190,10 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
private final List<Status> statusList;
private final boolean minified;
private final Timeline.TimeLineEnum timelineType;
public RemoteInstance.InstanceType type;
public PinnedTimeline pinnedTimeline;
private final boolean canBeFederated;
private final boolean checkRemotely;
public RemoteInstance.InstanceType type;
public PinnedTimeline pinnedTimeline;
public FetchMoreCallBack fetchMoreCallBack;
private Context context;
private boolean visiblePixelfed;

View File

@ -87,22 +87,15 @@ import app.fedilab.android.mastodon.viewmodel.mastodon.StatusesVM;
public class StatusDirectMessageAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static float measuredWidth = -1;
private final List<Status> statusList;
private Context context;
private RecyclerView mRecyclerView;
private static float measuredWidth = -1;
public StatusDirectMessageAdapter(List<Status> data) {
this.statusList = data;
}
@NotNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NotNull ViewGroup parent, int viewType) {
context = parent.getContext();
DrawerStatusChatBinding itemBinding = DrawerStatusChatBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
return new StatusChatViewHolder(itemBinding);
}
public static void loadAndAddAttachment(Context context, LayoutMediaBinding layoutMediaBinding,
StatusChatViewHolder holder,
RecyclerView.Adapter<RecyclerView.ViewHolder> adapter,
@ -214,6 +207,14 @@ public class StatusDirectMessageAdapter extends RecyclerView.Adapter<RecyclerVie
}
@NotNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NotNull ViewGroup parent, int viewType) {
context = parent.getContext();
DrawerStatusChatBinding itemBinding = DrawerStatusChatBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
return new StatusChatViewHolder(itemBinding);
}
@Override
public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
@ -227,15 +228,6 @@ public class StatusDirectMessageAdapter extends RecyclerView.Adapter<RecyclerVie
return statusList.size();
}
public static class StatusChatViewHolder extends RecyclerView.ViewHolder {
DrawerStatusChatBinding binding;
StatusChatViewHolder(DrawerStatusChatBinding itemView) {
super(itemView.getRoot());
binding = itemView;
}
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
@ -675,4 +667,13 @@ public class StatusDirectMessageAdapter extends RecyclerView.Adapter<RecyclerVie
holder.binding.media.mediaContainer.setVisibility(View.GONE);
}
}
public static class StatusChatViewHolder extends RecyclerView.ViewHolder {
DrawerStatusChatBinding binding;
StatusChatViewHolder(DrawerStatusChatBinding itemView) {
super(itemView.getRoot());
binding = itemView;
}
}
}

View File

@ -43,6 +43,7 @@ public class FragmentThemingSettings extends PreferenceFragmentCompat implements
boolean prefChanged = false;
@Override
public void onCreatePreferences(Bundle bundle, String s) {
createPref();

View File

@ -108,7 +108,7 @@ public class FragmentMastodonDirectMessage extends Fragment {
private Status firstStatus;
private boolean pullToRefresh;
private String user_token, user_instance;
private Status statusCompose;
private final BroadcastReceiver broadcast_data = new BroadcastReceiver() {
@Override
public void onReceive(android.content.Context context, Intent intent) {
@ -126,7 +126,6 @@ public class FragmentMastodonDirectMessage extends Fragment {
}
}
};
private Status statusCompose;
public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {

View File

@ -65,6 +65,9 @@ public class FragmentMastodonNotification extends Fragment implements Notificati
private boolean flagLoading;
private List<Notification> notificationList;
private NotificationAdapter notificationAdapter;
private boolean isViewInitialized;
private Notifications initialNotifications;
private String max_id, min_id, min_id_fetch_more, max_id_fetch_more;
private final BroadcastReceiver receive_action = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
@ -108,9 +111,6 @@ public class FragmentMastodonNotification extends Fragment implements Notificati
}
}
};
private boolean isViewInitialized;
private Notifications initialNotifications;
private String max_id, min_id, min_id_fetch_more, max_id_fetch_more;
private LinearLayoutManager mLayoutManager;
private NotificationTypeEnum notificationType;
private boolean aggregateNotification;

View File

@ -73,9 +73,9 @@ import es.dmoral.toasty.Toasty;
public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.FetchMoreCallBack {
private boolean scrollingUp;
private static final int PRELOAD_AHEAD_ITEMS = 10;
public UpdateCounters update;
private boolean scrollingUp;
private FragmentPaginationBinding binding;
private TimelinesVM timelinesVM;
private AccountsVM accountsVM;
@ -87,10 +87,6 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
private StatusAdapter statusAdapter;
private Timeline.TimeLineEnum timelineType;
private List<Status> timelineStatuses;
private boolean retry_for_home_done;
private String lemmy_post_id;
//Handle actions that can be done in other fragments
private final BroadcastReceiver receive_action = new BroadcastReceiver() {
@Override
@ -180,6 +176,8 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
}
}
};
private boolean retry_for_home_done;
private String lemmy_post_id;
private boolean checkRemotely;
private String accountIDInRemoteInstance;
private boolean isViewInitialized;

View File

@ -91,8 +91,6 @@ public class FragmentNotificationContainer extends Fragment {
dialogBuilder.setView(dialogView.getRoot());
boolean displayAllCategory = sharedpreferences.getBoolean(getString(R.string.SET_DISPLAY_ALL_NOTIFICATIONS_TYPE) + BaseMainActivity.currentUserID + BaseMainActivity.currentInstance, false);
dialogView.displayAllCategories.setChecked(displayAllCategory);
dialogView.displayAllCategories.setOnCheckedChangeListener((compoundButton, checked) -> {

View File

@ -205,6 +205,8 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
private boolean isShowingTrackSelectionDialog;
private Status status;
private int flags;
private boolean humanInteraction;
public static void hideKeyboard(Activity activity) {
if (activity != null && activity.getWindow() != null) {
activity.getWindow().getDecorView();
@ -215,8 +217,6 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
}
}
private boolean humanInteraction;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

View File

@ -88,7 +88,6 @@ public class ShowAccountActivity extends BaseBarActivity {
}
manageAccount();
AccountsVM viewModel = new ViewModelProvider(ShowAccountActivity.this).get(AccountsVM.class);
viewModel.getAccount(accountAcct == null ? account.getUsername() + "@" + account.getHost() : accountAcct).observe(ShowAccountActivity.this, this::manageViewAccounts);

View File

@ -20,6 +20,8 @@ import com.google.gson.annotations.SerializedName;
public class OauthParams {
@SerializedName("x_peertube_otp")
public String x_peertube_otp;
@SerializedName("client_id")
private String client_id;
@SerializedName("client_secret")
@ -44,9 +46,6 @@ public class OauthParams {
private String code;
@SerializedName("redirect_uri")
private String redirect_uri;
@SerializedName("x_peertube_otp")
public String x_peertube_otp;
public String getClient_secret() {
return client_secret;

View File

@ -45,10 +45,8 @@ import app.fedilab.android.peertube.helper.RoundedBackgroundSpan;
public class InstanceAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private final List<Instance> instances;
private Context context;
public ActionClick actionClick;
private Context context;
public InstanceAdapter(List<Instance> instances) {
this.instances = instances;
@ -159,6 +157,10 @@ public class InstanceAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
}
public interface ActionClick {
void instance(String instance);
}
static class ViewHolder extends RecyclerView.ViewHolder {
DrawerInstancePeertubeBinding binding;
@ -167,8 +169,4 @@ public class InstanceAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
binding = itemView;
}
}
public interface ActionClick {
void instance(String instance);
}
}

View File

@ -91,6 +91,18 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
private ChannelData.Channel forChannel;
private AccountData.PeertubeAccount forAccount;
public PeertubeAdapter(List<VideoData.Video> videos, TimelineVM.TimelineType timelineType, boolean sepiaSearch, ChannelData.Channel forChannel, AccountData.PeertubeAccount forAccount) {
this.videos = videos;
this.timelineType = timelineType;
this.sepiaSearch = sepiaSearch || timelineType == SEPIA_SEARCH;
this.forChannel = forChannel;
this.forAccount = forAccount;
}
public PeertubeAdapter(List<VideoData.Video> videos) {
this.videos = videos;
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
@ -107,19 +119,6 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
}
public PeertubeAdapter(List<VideoData.Video> videos, TimelineVM.TimelineType timelineType, boolean sepiaSearch, ChannelData.Channel forChannel, AccountData.PeertubeAccount forAccount) {
this.videos = videos;
this.timelineType = timelineType;
this.sepiaSearch = sepiaSearch || timelineType == SEPIA_SEARCH;
this.forChannel = forChannel;
this.forAccount = forAccount;
}
public PeertubeAdapter(List<VideoData.Video> videos) {
this.videos = videos;
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
@ -509,13 +508,6 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
}
enum typeOfTimeline {
CLASSIC,
LIST
}
public void manageVIewPlaylists(VideoData.Video video, APIResponse apiResponse) {
if (apiResponse.getError() != null) {
return;
@ -667,6 +659,11 @@ public class PeertubeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
}
enum typeOfTimeline {
CLASSIC,
LIST
}
public interface RelationShipListener {
Map<String, Boolean> getRelationShip();
}

View File

@ -15,8 +15,6 @@ package app.fedilab.android.peertube.drawer;
* see <http://www.gnu.org/licenses>. */
import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;

View File

@ -60,8 +60,7 @@ public class DisplayNotificationsFragment extends Fragment {
public final static int AUTO_INSTANCE_FOLLOWING = 14;
public final static int MY_VIDEO_REPPORT_SUCCESS = 15;
public final static int ABUSE_NEW_MESSAGE = 16;
FragmentRecyclerviewPeertubeBinding binding;
private boolean flag_loading;
private Context context;
private PeertubeNotificationsListAdapter peertubeNotificationsListAdapter;
@ -69,7 +68,6 @@ public class DisplayNotificationsFragment extends Fragment {
private List<Notification> notifications;
private boolean firstLoad;
private NotificationsVM viewModel;
FragmentRecyclerviewPeertubeBinding binding;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

View File

@ -171,7 +171,6 @@ public class DisplayOverviewFragment extends Fragment implements PeertubeAdapter
}
@Override
public void onStop() {
super.onStop();

View File

@ -841,11 +841,6 @@ public class Helper {
}
}
public interface PermissionGranted {
void proceed();
}
public static String readFileFromAssets(Context context, String filename) {
String json;
try {
@ -862,4 +857,9 @@ public class Helper {
return json;
}
public interface PermissionGranted {
void proceed();
}
}

View File

@ -206,8 +206,8 @@ public class Sqlite extends SQLiteOpenHelper {
+ COL_USER_ID + " TEXT NOT NULL, "
+ COL_TYPE + " TEXT NOT NULL, "
+ COL_MUTED_ACCOUNTS + " TEXT)";
public static SQLiteDatabase db;
private static Sqlite sInstance;
private final String CREATE_TABLE_STORED_INSTANCES = "CREATE TABLE "
+ TABLE_BOOKMARKED_INSTANCES + "("
+ COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
@ -215,12 +215,10 @@ public class Sqlite extends SQLiteOpenHelper {
+ COL_USER_ID + " TEXT NOT NULL, "
+ COL_ABOUT + " TEXT NOT NULL, "
+ COL_USER_INSTANCE + " TEXT NOT NULL)";
private final String CREATE_TABLE_CACHE_TAGS = "CREATE TABLE "
+ TABLE_CACHE_TAGS + "("
+ COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ COL_TAG + " TEXT NOT NULL)";
private final String CREATE_TABLE_TIMELINE_CACHE_LOGS = "CREATE TABLE "
+ TABLE_TIMELINE_CACHE_LOGS + "("
+ COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
@ -236,10 +234,6 @@ public class Sqlite extends SQLiteOpenHelper {
+ COL_CREATED_AT + " TEXT NOT NULL)";
public static SQLiteDatabase db;
private static Sqlite sInstance;
public Sqlite(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
super(context, name, factory, version);
}