From b298fbfa3eb1d2a7648757a69958c287efcabb4b Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 2 Jan 2021 13:38:58 +0100 Subject: [PATCH] Some changes --- .../fedilab/fedilabtube/AccountActivity.java | 73 +++++++++---------- .../fedilab/fedilabtube/PeertubeActivity.java | 17 +++-- app/src/main/res/layout/activity_account.xml | 13 +++- app/src/main/res/values/strings.xml | 1 + 4 files changed, 57 insertions(+), 47 deletions(-) diff --git a/app/src/main/java/app/fedilab/fedilabtube/AccountActivity.java b/app/src/main/java/app/fedilab/fedilabtube/AccountActivity.java index b723a11..40966ff 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/AccountActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/AccountActivity.java @@ -17,7 +17,9 @@ package app.fedilab.fedilabtube; import android.content.Intent; import android.content.SharedPreferences; import android.database.sqlite.SQLiteDatabase; +import android.os.Build; import android.os.Bundle; +import android.text.Html; import android.text.SpannableString; import android.text.Spanned; import android.text.style.ForegroundColorSpan; @@ -25,9 +27,6 @@ import android.text.style.UnderlineSpan; import android.view.Menu; import android.view.MenuItem; import android.view.View; -import android.widget.Button; -import android.widget.ImageView; -import android.widget.TextView; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; @@ -38,13 +37,13 @@ import androidx.fragment.app.FragmentStatePagerAdapter; import androidx.viewpager.widget.PagerAdapter; import androidx.viewpager.widget.ViewPager; -import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.tabs.TabLayout; import org.jetbrains.annotations.NotNull; import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI; import app.fedilab.fedilabtube.client.data.AccountData.Account; +import app.fedilab.fedilabtube.databinding.ActivityAccountBinding; import app.fedilab.fedilabtube.fragment.DisplayAccountsFragment; import app.fedilab.fedilabtube.fragment.DisplayChannelsFragment; import app.fedilab.fedilabtube.fragment.DisplayNotificationsFragment; @@ -57,15 +56,14 @@ import app.fedilab.fedilabtube.sqlite.Sqlite; public class AccountActivity extends AppCompatActivity { - private ViewPager mPager; - private TabLayout tabLayout; - + private ActivityAccountBinding binding; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - - setContentView(R.layout.activity_account); + binding = ActivityAccountBinding.inflate(getLayoutInflater()); + View view = binding.getRoot(); + setContentView(view); if (getSupportActionBar() != null) getSupportActionBar().setDisplayHomeAsUpEnabled(true); @@ -80,29 +78,23 @@ public class AccountActivity extends AppCompatActivity { SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null); - TextView instanceView = findViewById(R.id.instance); Account account = new AccountDAO(AccountActivity.this, db).getAccountByToken(token); if (account == null) { Helper.logoutCurrentUser(AccountActivity.this, null); return; } - ImageView profile_picture = findViewById(R.id.profile_picture); - TextView username = findViewById(R.id.username); - TextView displayname = findViewById(R.id.displayname); setTitle(String.format("@%s", account.getUsername())); - Helper.loadGiF(AccountActivity.this, account.getAvatar().getPath(), profile_picture); - username.setText(String.format("@%s", account.getUsername())); - displayname.setText(account.getDisplayName()); + Helper.loadGiF(AccountActivity.this, account.getAvatar().getPath(), binding.profilePicture); + binding.username.setText(String.format("@%s", account.getUsername())); + binding.displayname.setText(account.getDisplayName()); - instanceView.setText(account.getHost()); - FloatingActionButton edit_profile = findViewById(R.id.edit_profile); - edit_profile.setOnClickListener(v -> startActivity(new Intent(AccountActivity.this, MyAccountActivity.class))); + binding.instance.setText(account.getHost()); + binding.editProfile.setOnClickListener(v -> startActivity(new Intent(AccountActivity.this, MyAccountActivity.class))); - Button logout_button = findViewById(R.id.logout_button); - logout_button.setOnClickListener(v -> { + binding.logoutButton.setOnClickListener(v -> { AlertDialog.Builder dialogBuilderLogoutAccount = new AlertDialog.Builder(AccountActivity.this); dialogBuilderLogoutAccount.setMessage(getString(R.string.logout_account_confirmation, account.getUsername(), account.getHost())); dialogBuilderLogoutAccount.setPositiveButton(R.string.action_logout, (dialog, id) -> { @@ -114,24 +106,22 @@ public class AccountActivity extends AppCompatActivity { alertDialogLogoutAccount.show(); }); - Button settings = findViewById(R.id.settings); - settings.setOnClickListener(v -> { + binding.settings.setOnClickListener(v -> { Intent intent = new Intent(AccountActivity.this, SettingsActivity.class); startActivity(intent); }); - tabLayout = findViewById(R.id.account_tabLayout); - mPager = findViewById(R.id.account_viewpager); + if (Helper.isLoggedIn(AccountActivity.this)) { - tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.title_notifications))); - tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.title_muted))); - tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.title_channel))); + binding.accountTabLayout.addTab(binding.accountTabLayout.newTab().setText(getString(R.string.title_notifications))); + binding.accountTabLayout.addTab(binding.accountTabLayout.newTab().setText(getString(R.string.title_muted))); + binding.accountTabLayout.addTab(binding.accountTabLayout.newTab().setText(getString(R.string.title_channel))); - mPager.setOffscreenPageLimit(3); + binding.accountViewpager.setOffscreenPageLimit(3); - mPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { + binding.accountViewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { @@ -139,7 +129,7 @@ public class AccountActivity extends AppCompatActivity { @Override public void onPageSelected(int position) { - TabLayout.Tab tab = tabLayout.getTabAt(position); + TabLayout.Tab tab = binding.accountTabLayout.getTabAt(position); if (tab != null) tab.select(); } @@ -151,10 +141,10 @@ public class AccountActivity extends AppCompatActivity { }); - tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { + binding.accountTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { - mPager.setCurrentItem(tab.getPosition()); + binding.accountViewpager.setCurrentItem(tab.getPosition()); } @Override @@ -165,8 +155,8 @@ public class AccountActivity extends AppCompatActivity { @Override public void onTabReselected(TabLayout.Tab tab) { Fragment fragment = null; - if (mPager.getAdapter() != null) - fragment = (Fragment) mPager.getAdapter().instantiateItem(mPager, tab.getPosition()); + if (binding.accountViewpager.getAdapter() != null) + fragment = (Fragment) binding.accountViewpager.getAdapter().instantiateItem(binding.accountViewpager, tab.getPosition()); switch (tab.getPosition()) { case 0: if (fragment != null) { @@ -191,10 +181,17 @@ public class AccountActivity extends AppCompatActivity { }); PagerAdapter mPagerAdapter = new AccountsPagerAdapter(getSupportFragmentManager()); - mPager.setAdapter(mPagerAdapter); + binding.accountViewpager.setAdapter(mPagerAdapter); } else { - tabLayout.setVisibility(View.GONE); - mPager.setVisibility(View.GONE); + binding.accountTabLayout.setVisibility(View.GONE); + binding.accountViewpager.setVisibility(View.GONE); + binding.editProfile.setVisibility(View.GONE); + binding.remoteAccount.setVisibility(View.VISIBLE); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + binding.remoteAccount.setText(Html.fromHtml(getString(R.string.remote_account_from, account.getSoftware()), Html.FROM_HTML_MODE_LEGACY)); + else + binding.remoteAccount.setText(Html.fromHtml(getString(R.string.remote_account_from, account.getSoftware()))); } } diff --git a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java index 80653b8..af2ceec 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java @@ -174,6 +174,7 @@ import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.REPL import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.REPORT_ACCOUNT; import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.REPORT_VIDEO; import static app.fedilab.fedilabtube.helper.Helper.CAST_ID; +import static app.fedilab.fedilabtube.helper.Helper.canMakeAction; import static app.fedilab.fedilabtube.helper.Helper.getAttColor; import static app.fedilab.fedilabtube.helper.Helper.isLoggedIn; import static app.fedilab.fedilabtube.helper.Helper.loadGiF; @@ -309,8 +310,8 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd max_id = "0"; SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); - String token = Helper.getToken(PeertubeActivity.this); - if (Helper.isLoggedIn(PeertubeActivity.this) && !sepiaSearch) { + String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null); + if (Helper.canMakeAction(PeertubeActivity.this) && !sepiaSearch) { Account account = new AccountDAO(PeertubeActivity.this, db).getAccountByToken(token); Helper.loadGiF(PeertubeActivity.this, account.getAvatar() != null ? account.getAvatar().getPath() : null, binding.myPp); } @@ -375,7 +376,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd } } }); - if (!Helper.isLoggedIn(PeertubeActivity.this) || sepiaSearch) { + if (!Helper.canMakeAction(PeertubeActivity.this) || sepiaSearch) { binding.writeCommentContainer.setVisibility(View.GONE); } playInMinimized = sharedpreferences.getBoolean(getString(R.string.set_video_minimize_choice), true); @@ -484,7 +485,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd openFullscreenDialog(); } binding.postCommentButton.setOnClickListener(v -> { - if (isLoggedIn(PeertubeActivity.this) && !sepiaSearch) { + if (canMakeAction(PeertubeActivity.this) && !sepiaSearch) { openPostComment(null, 0); } else { if (sepiaSearch) { @@ -1082,7 +1083,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd PlaylistsVM viewModel = new ViewModelProvider(this).get(PlaylistsVM.class); viewModel.videoExists(videoIds).observe(this, this::manageVIewPlaylist); - if (!Helper.isLoggedIn(PeertubeActivity.this) || sepiaSearch) { + if (!Helper.canMakeAction(PeertubeActivity.this) || sepiaSearch) { binding.writeCommentContainer.setVisibility(View.GONE); } @@ -1450,14 +1451,14 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd private void fetchComments() { if (peertube.isCommentsEnabled()) { - if (Helper.isLoggedIn(PeertubeActivity.this)) { + if (Helper.canMakeAction(PeertubeActivity.this)) { binding.postCommentButton.setVisibility(View.VISIBLE); } else { binding.postCommentButton.setVisibility(View.GONE); } CommentVM commentViewModel = new ViewModelProvider(PeertubeActivity.this).get(CommentVM.class); commentViewModel.getThread(sepiaSearch ? peertubeInstance : null, videoUuid, max_id).observe(PeertubeActivity.this, this::manageVIewComment); - if (Helper.isLoggedIn(PeertubeActivity.this) && !sepiaSearch) { + if (Helper.canMakeAction(PeertubeActivity.this) && !sepiaSearch) { binding.writeCommentContainer.setVisibility(View.VISIBLE); } binding.peertubeComments.setVisibility(View.VISIBLE); @@ -2019,7 +2020,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd private void sendComment(Comment comment, int position) { - if (isLoggedIn(PeertubeActivity.this) && !sepiaSearch) { + if (canMakeAction(PeertubeActivity.this) && !sepiaSearch) { if (comment == null) { String commentStr = binding.addCommentWrite.getText() != null ? binding.addCommentWrite.getText().toString() : ""; if (commentStr.trim().length() > 0) { diff --git a/app/src/main/res/layout/activity_account.xml b/app/src/main/res/layout/activity_account.xml index 164c08f..b384728 100644 --- a/app/src/main/res/layout/activity_account.xml +++ b/app/src/main/res/layout/activity_account.xml @@ -159,6 +159,16 @@ app:tabTextColor="@android:color/white" /> + + android:visibility="gone" + tools:ignore="ContentDescription" /> \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1be51db..b3afdee 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -454,5 +454,6 @@ The video should not have more than 5 tags! Watermark An error occurred! The instance did not return an authorisation code! + %1$s remote account connected with the app.\n\nYou can proceed to some limited actions. \ No newline at end of file