Some changes
This commit is contained in:
parent
d83929f80a
commit
b298fbfa3e
|
@ -17,7 +17,9 @@ package app.fedilab.fedilabtube;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.text.Html;
|
||||||
import android.text.SpannableString;
|
import android.text.SpannableString;
|
||||||
import android.text.Spanned;
|
import android.text.Spanned;
|
||||||
import android.text.style.ForegroundColorSpan;
|
import android.text.style.ForegroundColorSpan;
|
||||||
|
@ -25,9 +27,6 @@ import android.text.style.UnderlineSpan;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
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.AlertDialog;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
@ -38,13 +37,13 @@ import androidx.fragment.app.FragmentStatePagerAdapter;
|
||||||
import androidx.viewpager.widget.PagerAdapter;
|
import androidx.viewpager.widget.PagerAdapter;
|
||||||
import androidx.viewpager.widget.ViewPager;
|
import androidx.viewpager.widget.ViewPager;
|
||||||
|
|
||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
|
||||||
import com.google.android.material.tabs.TabLayout;
|
import com.google.android.material.tabs.TabLayout;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
|
import app.fedilab.fedilabtube.client.RetrofitPeertubeAPI;
|
||||||
import app.fedilab.fedilabtube.client.data.AccountData.Account;
|
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.DisplayAccountsFragment;
|
||||||
import app.fedilab.fedilabtube.fragment.DisplayChannelsFragment;
|
import app.fedilab.fedilabtube.fragment.DisplayChannelsFragment;
|
||||||
import app.fedilab.fedilabtube.fragment.DisplayNotificationsFragment;
|
import app.fedilab.fedilabtube.fragment.DisplayNotificationsFragment;
|
||||||
|
@ -57,15 +56,14 @@ import app.fedilab.fedilabtube.sqlite.Sqlite;
|
||||||
public class AccountActivity extends AppCompatActivity {
|
public class AccountActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
|
||||||
private ViewPager mPager;
|
private ActivityAccountBinding binding;
|
||||||
private TabLayout tabLayout;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
binding = ActivityAccountBinding.inflate(getLayoutInflater());
|
||||||
setContentView(R.layout.activity_account);
|
View view = binding.getRoot();
|
||||||
|
setContentView(view);
|
||||||
if (getSupportActionBar() != null)
|
if (getSupportActionBar() != null)
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
|
||||||
|
@ -80,29 +78,23 @@ public class AccountActivity extends AppCompatActivity {
|
||||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||||
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
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);
|
Account account = new AccountDAO(AccountActivity.this, db).getAccountByToken(token);
|
||||||
if (account == null) {
|
if (account == null) {
|
||||||
Helper.logoutCurrentUser(AccountActivity.this, null);
|
Helper.logoutCurrentUser(AccountActivity.this, null);
|
||||||
return;
|
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()));
|
setTitle(String.format("@%s", account.getUsername()));
|
||||||
|
|
||||||
Helper.loadGiF(AccountActivity.this, account.getAvatar().getPath(), profile_picture);
|
Helper.loadGiF(AccountActivity.this, account.getAvatar().getPath(), binding.profilePicture);
|
||||||
username.setText(String.format("@%s", account.getUsername()));
|
binding.username.setText(String.format("@%s", account.getUsername()));
|
||||||
displayname.setText(account.getDisplayName());
|
binding.displayname.setText(account.getDisplayName());
|
||||||
|
|
||||||
instanceView.setText(account.getHost());
|
binding.instance.setText(account.getHost());
|
||||||
FloatingActionButton edit_profile = findViewById(R.id.edit_profile);
|
binding.editProfile.setOnClickListener(v -> startActivity(new Intent(AccountActivity.this, MyAccountActivity.class)));
|
||||||
edit_profile.setOnClickListener(v -> startActivity(new Intent(AccountActivity.this, MyAccountActivity.class)));
|
|
||||||
|
|
||||||
Button logout_button = findViewById(R.id.logout_button);
|
binding.logoutButton.setOnClickListener(v -> {
|
||||||
logout_button.setOnClickListener(v -> {
|
|
||||||
AlertDialog.Builder dialogBuilderLogoutAccount = new AlertDialog.Builder(AccountActivity.this);
|
AlertDialog.Builder dialogBuilderLogoutAccount = new AlertDialog.Builder(AccountActivity.this);
|
||||||
dialogBuilderLogoutAccount.setMessage(getString(R.string.logout_account_confirmation, account.getUsername(), account.getHost()));
|
dialogBuilderLogoutAccount.setMessage(getString(R.string.logout_account_confirmation, account.getUsername(), account.getHost()));
|
||||||
dialogBuilderLogoutAccount.setPositiveButton(R.string.action_logout, (dialog, id) -> {
|
dialogBuilderLogoutAccount.setPositiveButton(R.string.action_logout, (dialog, id) -> {
|
||||||
|
@ -114,24 +106,22 @@ public class AccountActivity extends AppCompatActivity {
|
||||||
alertDialogLogoutAccount.show();
|
alertDialogLogoutAccount.show();
|
||||||
});
|
});
|
||||||
|
|
||||||
Button settings = findViewById(R.id.settings);
|
binding.settings.setOnClickListener(v -> {
|
||||||
settings.setOnClickListener(v -> {
|
|
||||||
Intent intent = new Intent(AccountActivity.this, SettingsActivity.class);
|
Intent intent = new Intent(AccountActivity.this, SettingsActivity.class);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
});
|
});
|
||||||
|
|
||||||
tabLayout = findViewById(R.id.account_tabLayout);
|
|
||||||
mPager = findViewById(R.id.account_viewpager);
|
|
||||||
|
|
||||||
if (Helper.isLoggedIn(AccountActivity.this)) {
|
if (Helper.isLoggedIn(AccountActivity.this)) {
|
||||||
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.title_notifications)));
|
binding.accountTabLayout.addTab(binding.accountTabLayout.newTab().setText(getString(R.string.title_notifications)));
|
||||||
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.title_muted)));
|
binding.accountTabLayout.addTab(binding.accountTabLayout.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_channel)));
|
||||||
|
|
||||||
mPager.setOffscreenPageLimit(3);
|
binding.accountViewpager.setOffscreenPageLimit(3);
|
||||||
|
|
||||||
|
|
||||||
mPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
binding.accountViewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||||
|
|
||||||
|
@ -139,7 +129,7 @@ public class AccountActivity extends AppCompatActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPageSelected(int position) {
|
public void onPageSelected(int position) {
|
||||||
TabLayout.Tab tab = tabLayout.getTabAt(position);
|
TabLayout.Tab tab = binding.accountTabLayout.getTabAt(position);
|
||||||
if (tab != null)
|
if (tab != null)
|
||||||
tab.select();
|
tab.select();
|
||||||
}
|
}
|
||||||
|
@ -151,10 +141,10 @@ public class AccountActivity extends AppCompatActivity {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
|
binding.accountTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onTabSelected(TabLayout.Tab tab) {
|
public void onTabSelected(TabLayout.Tab tab) {
|
||||||
mPager.setCurrentItem(tab.getPosition());
|
binding.accountViewpager.setCurrentItem(tab.getPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -165,8 +155,8 @@ public class AccountActivity extends AppCompatActivity {
|
||||||
@Override
|
@Override
|
||||||
public void onTabReselected(TabLayout.Tab tab) {
|
public void onTabReselected(TabLayout.Tab tab) {
|
||||||
Fragment fragment = null;
|
Fragment fragment = null;
|
||||||
if (mPager.getAdapter() != null)
|
if (binding.accountViewpager.getAdapter() != null)
|
||||||
fragment = (Fragment) mPager.getAdapter().instantiateItem(mPager, tab.getPosition());
|
fragment = (Fragment) binding.accountViewpager.getAdapter().instantiateItem(binding.accountViewpager, tab.getPosition());
|
||||||
switch (tab.getPosition()) {
|
switch (tab.getPosition()) {
|
||||||
case 0:
|
case 0:
|
||||||
if (fragment != null) {
|
if (fragment != null) {
|
||||||
|
@ -191,10 +181,17 @@ public class AccountActivity extends AppCompatActivity {
|
||||||
});
|
});
|
||||||
|
|
||||||
PagerAdapter mPagerAdapter = new AccountsPagerAdapter(getSupportFragmentManager());
|
PagerAdapter mPagerAdapter = new AccountsPagerAdapter(getSupportFragmentManager());
|
||||||
mPager.setAdapter(mPagerAdapter);
|
binding.accountViewpager.setAdapter(mPagerAdapter);
|
||||||
} else {
|
} else {
|
||||||
tabLayout.setVisibility(View.GONE);
|
binding.accountTabLayout.setVisibility(View.GONE);
|
||||||
mPager.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())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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_ACCOUNT;
|
||||||
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.REPORT_VIDEO;
|
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.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.getAttColor;
|
||||||
import static app.fedilab.fedilabtube.helper.Helper.isLoggedIn;
|
import static app.fedilab.fedilabtube.helper.Helper.isLoggedIn;
|
||||||
import static app.fedilab.fedilabtube.helper.Helper.loadGiF;
|
import static app.fedilab.fedilabtube.helper.Helper.loadGiF;
|
||||||
|
@ -309,8 +310,8 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
||||||
max_id = "0";
|
max_id = "0";
|
||||||
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||||
String token = Helper.getToken(PeertubeActivity.this);
|
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||||
if (Helper.isLoggedIn(PeertubeActivity.this) && !sepiaSearch) {
|
if (Helper.canMakeAction(PeertubeActivity.this) && !sepiaSearch) {
|
||||||
Account account = new AccountDAO(PeertubeActivity.this, db).getAccountByToken(token);
|
Account account = new AccountDAO(PeertubeActivity.this, db).getAccountByToken(token);
|
||||||
Helper.loadGiF(PeertubeActivity.this, account.getAvatar() != null ? account.getAvatar().getPath() : null, binding.myPp);
|
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);
|
binding.writeCommentContainer.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
playInMinimized = sharedpreferences.getBoolean(getString(R.string.set_video_minimize_choice), true);
|
playInMinimized = sharedpreferences.getBoolean(getString(R.string.set_video_minimize_choice), true);
|
||||||
|
@ -484,7 +485,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
||||||
openFullscreenDialog();
|
openFullscreenDialog();
|
||||||
}
|
}
|
||||||
binding.postCommentButton.setOnClickListener(v -> {
|
binding.postCommentButton.setOnClickListener(v -> {
|
||||||
if (isLoggedIn(PeertubeActivity.this) && !sepiaSearch) {
|
if (canMakeAction(PeertubeActivity.this) && !sepiaSearch) {
|
||||||
openPostComment(null, 0);
|
openPostComment(null, 0);
|
||||||
} else {
|
} else {
|
||||||
if (sepiaSearch) {
|
if (sepiaSearch) {
|
||||||
|
@ -1082,7 +1083,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
||||||
PlaylistsVM viewModel = new ViewModelProvider(this).get(PlaylistsVM.class);
|
PlaylistsVM viewModel = new ViewModelProvider(this).get(PlaylistsVM.class);
|
||||||
viewModel.videoExists(videoIds).observe(this, this::manageVIewPlaylist);
|
viewModel.videoExists(videoIds).observe(this, this::manageVIewPlaylist);
|
||||||
|
|
||||||
if (!Helper.isLoggedIn(PeertubeActivity.this) || sepiaSearch) {
|
if (!Helper.canMakeAction(PeertubeActivity.this) || sepiaSearch) {
|
||||||
binding.writeCommentContainer.setVisibility(View.GONE);
|
binding.writeCommentContainer.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1450,14 +1451,14 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
|
||||||
|
|
||||||
private void fetchComments() {
|
private void fetchComments() {
|
||||||
if (peertube.isCommentsEnabled()) {
|
if (peertube.isCommentsEnabled()) {
|
||||||
if (Helper.isLoggedIn(PeertubeActivity.this)) {
|
if (Helper.canMakeAction(PeertubeActivity.this)) {
|
||||||
binding.postCommentButton.setVisibility(View.VISIBLE);
|
binding.postCommentButton.setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
binding.postCommentButton.setVisibility(View.GONE);
|
binding.postCommentButton.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
CommentVM commentViewModel = new ViewModelProvider(PeertubeActivity.this).get(CommentVM.class);
|
CommentVM commentViewModel = new ViewModelProvider(PeertubeActivity.this).get(CommentVM.class);
|
||||||
commentViewModel.getThread(sepiaSearch ? peertubeInstance : null, videoUuid, max_id).observe(PeertubeActivity.this, this::manageVIewComment);
|
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.writeCommentContainer.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
binding.peertubeComments.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) {
|
private void sendComment(Comment comment, int position) {
|
||||||
if (isLoggedIn(PeertubeActivity.this) && !sepiaSearch) {
|
if (canMakeAction(PeertubeActivity.this) && !sepiaSearch) {
|
||||||
if (comment == null) {
|
if (comment == null) {
|
||||||
String commentStr = binding.addCommentWrite.getText() != null ? binding.addCommentWrite.getText().toString() : "";
|
String commentStr = binding.addCommentWrite.getText() != null ? binding.addCommentWrite.getText().toString() : "";
|
||||||
if (commentStr.trim().length() > 0) {
|
if (commentStr.trim().length() > 0) {
|
||||||
|
|
|
@ -159,6 +159,16 @@
|
||||||
app:tabTextColor="@android:color/white" />
|
app:tabTextColor="@android:color/white" />
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/remote_account"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:layout_margin="20dp"
|
||||||
|
android:autoLink="web"
|
||||||
|
android:gravity="center"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
<androidx.viewpager.widget.ViewPager
|
<androidx.viewpager.widget.ViewPager
|
||||||
android:id="@+id/account_viewpager"
|
android:id="@+id/account_viewpager"
|
||||||
|
@ -175,5 +185,6 @@
|
||||||
android:layout_margin="@dimen/fab_margin_button"
|
android:layout_margin="@dimen/fab_margin_button"
|
||||||
android:src="@drawable/ic_baseline_add_24"
|
android:src="@drawable/ic_baseline_add_24"
|
||||||
android:tint="@android:color/white"
|
android:tint="@android:color/white"
|
||||||
android:visibility="gone" />
|
android:visibility="gone"
|
||||||
|
tools:ignore="ContentDescription" />
|
||||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
|
@ -454,5 +454,6 @@
|
||||||
<string name="max_tag_size">The video should not have more than 5 tags!</string>
|
<string name="max_tag_size">The video should not have more than 5 tags!</string>
|
||||||
<string name="watermark">Watermark</string>
|
<string name="watermark">Watermark</string>
|
||||||
<string name="toast_code_error">An error occurred! The instance did not return an authorisation code!</string>
|
<string name="toast_code_error">An error occurred! The instance did not return an authorisation code!</string>
|
||||||
|
<string name="remote_account_from"><b>%1$s</b> remote account connected with the app.\n\nYou can proceed to some limited actions.</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in New Issue