mirror of
				https://codeberg.org/tom79/Fedilab.git
				synced 2025-10-20 11:20:16 +03:00 
			
		
		
		
	Some changes
This commit is contained in:
		
							parent
							
								
									dddef9706d
								
							
						
					
					
						commit
						ffe7dbf1dd
					
				
					 9 changed files with 301 additions and 187 deletions
				
			
		|  | @ -24,6 +24,7 @@ import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_TOKEN; | ||||||
| import static app.fedilab.android.mastodon.helper.Helper.displayReleaseNotesIfNeeded; | import static app.fedilab.android.mastodon.helper.Helper.displayReleaseNotesIfNeeded; | ||||||
| import static app.fedilab.android.mastodon.helper.ThemeHelper.fetchAccentColor; | import static app.fedilab.android.mastodon.helper.ThemeHelper.fetchAccentColor; | ||||||
| import static app.fedilab.android.mastodon.ui.drawer.StatusAdapter.sendAction; | import static app.fedilab.android.mastodon.ui.drawer.StatusAdapter.sendAction; | ||||||
|  | import static app.fedilab.android.peertube.activities.PeertubeMainActivity.typeOfConnection; | ||||||
| 
 | 
 | ||||||
| import android.Manifest; | import android.Manifest; | ||||||
| import android.annotation.SuppressLint; | import android.annotation.SuppressLint; | ||||||
|  | @ -374,6 +375,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt | ||||||
|                             } else if (accounts.get(0).peertube_account != null) { |                             } else if (accounts.get(0).peertube_account != null) { | ||||||
|                                 account = "@" + accounts.get(0).peertube_account.getAcct() + "@" + accounts.get(0).instance; |                                 account = "@" + accounts.get(0).peertube_account.getAcct() + "@" + accounts.get(0).instance; | ||||||
|                             } |                             } | ||||||
|  |                             typeOfConnection = PeertubeMainActivity.TypeOfConnection.NORMAL; | ||||||
|                             Toasty.info(activity, activity.getString(R.string.toast_account_changed, account), Toasty.LENGTH_LONG).show(); |                             Toasty.info(activity, activity.getString(R.string.toast_account_changed, account), Toasty.LENGTH_LONG).show(); | ||||||
|                             BaseMainActivity.currentToken = accounts.get(0).token; |                             BaseMainActivity.currentToken = accounts.get(0).token; | ||||||
|                             BaseMainActivity.currentUserID = accounts.get(0).user_id; |                             BaseMainActivity.currentUserID = accounts.get(0).user_id; | ||||||
|  | @ -546,6 +548,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt | ||||||
|                                             } else if (account.peertube_account != null) { |                                             } else if (account.peertube_account != null) { | ||||||
|                                                 acctForAccount = "@" + account.peertube_account.getUsername() + "@" + account.instance; |                                                 acctForAccount = "@" + account.peertube_account.getUsername() + "@" + account.instance; | ||||||
|                                             } |                                             } | ||||||
|  |                                             typeOfConnection = PeertubeMainActivity.TypeOfConnection.NORMAL; | ||||||
|                                             Toasty.info(activity, activity.getString(R.string.toast_account_changed, acctForAccount), Toasty.LENGTH_LONG).show(); |                                             Toasty.info(activity, activity.getString(R.string.toast_account_changed, acctForAccount), Toasty.LENGTH_LONG).show(); | ||||||
|                                             BaseMainActivity.currentToken = account.token; |                                             BaseMainActivity.currentToken = account.token; | ||||||
|                                             BaseMainActivity.currentUserID = account.user_id; |                                             BaseMainActivity.currentUserID = account.user_id; | ||||||
|  | @ -559,6 +562,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt | ||||||
|                                             editor.commit(); |                                             editor.commit(); | ||||||
|                                             //The user is now aut |                                             //The user is now aut | ||||||
|                                             //The user is now authenticated, it will be redirected to MainActivity |                                             //The user is now authenticated, it will be redirected to MainActivity | ||||||
|  | 
 | ||||||
|                                             Intent mainActivity = new Intent(activity, MainActivity.class); |                                             Intent mainActivity = new Intent(activity, MainActivity.class); | ||||||
|                                             activity.startActivity(mainActivity); |                                             activity.startActivity(mainActivity); | ||||||
|                                             activity.finish(); |                                             activity.finish(); | ||||||
|  | @ -711,6 +715,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt | ||||||
|                         } else if (account.peertube_account != null) { |                         } else if (account.peertube_account != null) { | ||||||
|                             acct = "@" + account.peertube_account.getUsername() + "@" + account.instance; |                             acct = "@" + account.peertube_account.getUsername() + "@" + account.instance; | ||||||
|                         } |                         } | ||||||
|  |                         typeOfConnection = PeertubeMainActivity.TypeOfConnection.NORMAL; | ||||||
|                         Toasty.info(activity, activity.getString(R.string.toast_account_changed, acct), Toasty.LENGTH_LONG).show(); |                         Toasty.info(activity, activity.getString(R.string.toast_account_changed, acct), Toasty.LENGTH_LONG).show(); | ||||||
|                         BaseMainActivity.currentToken = account.token; |                         BaseMainActivity.currentToken = account.token; | ||||||
|                         BaseMainActivity.currentUserID = account.user_id; |                         BaseMainActivity.currentUserID = account.user_id; | ||||||
|  | @ -1358,6 +1363,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt | ||||||
|                 bundle.putBoolean(Helper.ARG_PEERTUBE_NAV_REMOTE, true); |                 bundle.putBoolean(Helper.ARG_PEERTUBE_NAV_REMOTE, true); | ||||||
|                 intent.putExtras(bundle); |                 intent.putExtras(bundle); | ||||||
|                 startActivity(intent); |                 startActivity(intent); | ||||||
|  |                 finish(); | ||||||
|             } else if (id == R.id.nav_about_instance) { |             } else if (id == R.id.nav_about_instance) { | ||||||
|                 (new InstanceActivity()).show(getSupportFragmentManager(), null); |                 (new InstanceActivity()).show(getSupportFragmentManager(), null); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|  | @ -302,6 +302,9 @@ public class Helper { | ||||||
|     public static final String PREF_USER_TOKEN = "PREF_USER_TOKEN"; |     public static final String PREF_USER_TOKEN = "PREF_USER_TOKEN"; | ||||||
|     public static final String PREF_USER_ID = "PREF_USER_ID"; |     public static final String PREF_USER_ID = "PREF_USER_ID"; | ||||||
|     public static final String PREF_USER_INSTANCE = "PREF_USER_INSTANCE"; |     public static final String PREF_USER_INSTANCE = "PREF_USER_INSTANCE"; | ||||||
|  |     public static final String PREF_USER_INSTANCE_PEERTUBE_BROWSING = "PREF_USER_INSTANCE_PEERTUBE_BROWSING"; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|     public static final String PREF_USER_SOFTWARE = "PREF_USER_SOFTWARE"; |     public static final String PREF_USER_SOFTWARE = "PREF_USER_SOFTWARE"; | ||||||
|     public static final String PREF_IS_MODERATOR = "PREF_IS_MODERATOR"; |     public static final String PREF_IS_MODERATOR = "PREF_IS_MODERATOR"; | ||||||
|     public static final String PREF_IS_ADMINISTRATOR = "PREF_IS_ADMINISTRATOR"; |     public static final String PREF_IS_ADMINISTRATOR = "PREF_IS_ADMINISTRATOR"; | ||||||
|  |  | ||||||
|  | @ -14,7 +14,7 @@ package app.fedilab.android.peertube.activities; | ||||||
|  * You should have received a copy of the GNU General Public License along with Fedilab; if not, |  * You should have received a copy of the GNU General Public License along with Fedilab; if not, | ||||||
|  * see <http://www.gnu.org/licenses>. */ |  * see <http://www.gnu.org/licenses>. */ | ||||||
| 
 | 
 | ||||||
| import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_INSTANCE; | import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_INSTANCE_PEERTUBE_BROWSING; | ||||||
| import static app.fedilab.android.mastodon.helper.Helper.addFragment; | import static app.fedilab.android.mastodon.helper.Helper.addFragment; | ||||||
| import static app.fedilab.android.peertube.activities.PeertubeMainActivity.INSTANCE_ADDRESS; | import static app.fedilab.android.peertube.activities.PeertubeMainActivity.INSTANCE_ADDRESS; | ||||||
| import static app.fedilab.android.peertube.activities.PeertubeMainActivity.PICK_INSTANCE; | import static app.fedilab.android.peertube.activities.PeertubeMainActivity.PICK_INSTANCE; | ||||||
|  | @ -32,6 +32,8 @@ import android.widget.LinearLayout; | ||||||
| import android.widget.Toast; | import android.widget.Toast; | ||||||
| 
 | 
 | ||||||
| import androidx.appcompat.app.AlertDialog; | import androidx.appcompat.app.AlertDialog; | ||||||
|  | import androidx.fragment.app.FragmentManager; | ||||||
|  | import androidx.lifecycle.LifecycleOwner; | ||||||
| import androidx.lifecycle.ViewModelProvider; | import androidx.lifecycle.ViewModelProvider; | ||||||
| import androidx.preference.PreferenceManager; | import androidx.preference.PreferenceManager; | ||||||
| import androidx.recyclerview.widget.LinearLayoutManager; | import androidx.recyclerview.widget.LinearLayoutManager; | ||||||
|  | @ -65,33 +67,8 @@ public class ManageInstancesActivity extends BaseBarActivity implements AboutIns | ||||||
|     private AboutInstanceAdapter aboutInstanceAdapter; |     private AboutInstanceAdapter aboutInstanceAdapter; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|     @Override |  | ||||||
|     protected void onCreate(Bundle savedInstanceState) { |  | ||||||
|         super.onCreate(savedInstanceState); |  | ||||||
|         binding = ActivityManageInstancesPeertubeBinding.inflate(getLayoutInflater()); |  | ||||||
|         View view = binding.getRoot(); |  | ||||||
|         setContentView(view); |  | ||||||
|         if (getSupportActionBar() != null) { |  | ||||||
|             getSupportActionBar().setDisplayHomeAsUpEnabled(true); |  | ||||||
|             getSupportActionBar().setDisplayShowHomeEnabled(true); |  | ||||||
|         } |  | ||||||
|         binding.loader.setVisibility(View.VISIBLE); |  | ||||||
|         binding.noAction.setVisibility(View.GONE); |  | ||||||
|         binding.lvInstances.setVisibility(View.GONE); |  | ||||||
|         binding.actionButton.setOnClickListener(v -> showRadioButtonDialogFullInstances(ManageInstancesActivity.this)); |  | ||||||
|         aboutInstances = new ArrayList<>(); |  | ||||||
|         aboutInstanceAdapter = new AboutInstanceAdapter(this.aboutInstances); |  | ||||||
|         aboutInstanceAdapter.allInstancesRemoved = this; |  | ||||||
|         binding.lvInstances.setAdapter(aboutInstanceAdapter); |  | ||||||
|         LinearLayoutManager layoutManager |  | ||||||
|                 = new LinearLayoutManager(ManageInstancesActivity.this); |  | ||||||
|         binding.lvInstances.setLayoutManager(layoutManager); |  | ||||||
|         InfoInstanceVM viewModelInfoInstance = new ViewModelProvider(ManageInstancesActivity.this).get(InfoInstanceVM.class); |  | ||||||
|         viewModelInfoInstance.getInstances().observe(ManageInstancesActivity.this, this::manageVIewInfoInstance); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     @SuppressLint("ApplySharedPref") |     @SuppressLint("ApplySharedPref") | ||||||
|     private void showRadioButtonDialogFullInstances(Activity activity) { |     public static void showRadioButtonDialogFullInstances(Activity activity, FragmentManager fragmentManager) { | ||||||
|         SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity); |         SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity); | ||||||
|         AlertDialog.Builder alt_bld = new MaterialAlertDialogBuilder(activity); |         AlertDialog.Builder alt_bld = new MaterialAlertDialogBuilder(activity); | ||||||
|         alt_bld.setTitle(R.string.instance_choice); |         alt_bld.setTitle(R.string.instance_choice); | ||||||
|  | @ -116,7 +93,7 @@ public class ManageInstancesActivity extends BaseBarActivity implements AboutIns | ||||||
|                         WellKnownNodeinfo.NodeInfo instanceNodeInfo = new RetrofitPeertubeAPI(activity, newInstance, null).getNodeInfo(); |                         WellKnownNodeinfo.NodeInfo instanceNodeInfo = new RetrofitPeertubeAPI(activity, newInstance, null).getNodeInfo(); | ||||||
|                         if (instanceNodeInfo.getSoftware() != null && instanceNodeInfo.getSoftware().getName().trim().toLowerCase().compareTo("peertube") == 0) { |                         if (instanceNodeInfo.getSoftware() != null && instanceNodeInfo.getSoftware().getName().trim().toLowerCase().compareTo("peertube") == 0) { | ||||||
|                             SharedPreferences.Editor editor = sharedpreferences.edit(); |                             SharedPreferences.Editor editor = sharedpreferences.edit(); | ||||||
|                             editor.putString(PREF_USER_INSTANCE, newInstance); |                             editor.putString(PREF_USER_INSTANCE_PEERTUBE_BROWSING, newInstance); | ||||||
|                             editor.commit(); |                             editor.commit(); | ||||||
|                             newInstance = newInstance.trim().toLowerCase(); |                             newInstance = newInstance.trim().toLowerCase(); | ||||||
|                             InstanceData.AboutInstance aboutInstance = new RetrofitPeertubeAPI(activity, newInstance, null).getAboutInstance(); |                             InstanceData.AboutInstance aboutInstance = new RetrofitPeertubeAPI(activity, newInstance, null).getAboutInstance(); | ||||||
|  | @ -136,24 +113,49 @@ public class ManageInstancesActivity extends BaseBarActivity implements AboutIns | ||||||
|                 }).start()); |                 }).start()); | ||||||
|         alt_bld.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); |         alt_bld.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); | ||||||
|         alt_bld.setNeutralButton(R.string.help, (dialog, which) -> { |         alt_bld.setNeutralButton(R.string.help, (dialog, which) -> { | ||||||
|             getSupportFragmentManager().setFragmentResultListener(PICK_INSTANCE, this, (requestKey, result) -> { |             fragmentManager.setFragmentResultListener(PICK_INSTANCE, (LifecycleOwner) activity, (requestKey, result) -> { | ||||||
|                 new Thread(() -> { |                 new Thread(() -> { | ||||||
|                     String newInstance = result.getString(INSTANCE_ADDRESS); |                     String newInstance = result.getString(INSTANCE_ADDRESS); | ||||||
|                     InstanceData.AboutInstance aboutInstance = new RetrofitPeertubeAPI(ManageInstancesActivity.this, newInstance, null).getAboutInstance(); |                     InstanceData.AboutInstance aboutInstance = new RetrofitPeertubeAPI(activity, newInstance, null).getAboutInstance(); | ||||||
|                     SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); |                     SQLiteDatabase db = Sqlite.getInstance(activity, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); | ||||||
|                     new StoredInstanceDAO(ManageInstancesActivity.this, db).insertInstance(aboutInstance, newInstance); |                     new StoredInstanceDAO(activity, db).insertInstance(aboutInstance, newInstance); | ||||||
|                     runOnUiThread(() -> new Handler().post(() -> Helper.logoutNoRemoval(ManageInstancesActivity.this))); |                     activity.runOnUiThread(() -> new Handler().post(() -> Helper.logoutNoRemoval(activity))); | ||||||
|                 }).start(); |                 }).start(); | ||||||
|                 getSupportFragmentManager().clearFragmentResultListener(PICK_INSTANCE); |                 fragmentManager.clearFragmentResultListener(PICK_INSTANCE); | ||||||
|             }); |             }); | ||||||
|             addFragment( |             addFragment( | ||||||
|                     getSupportFragmentManager(), android.R.id.content, new FragmentLoginPickInstancePeertube(), |                     fragmentManager, android.R.id.content, new FragmentLoginPickInstancePeertube(), | ||||||
|                     null, null, FragmentLoginPickInstancePeertube.class.getName()); |                     null, null, FragmentLoginPickInstancePeertube.class.getName()); | ||||||
|         }); |         }); | ||||||
|         AlertDialog alert = alt_bld.create(); |         AlertDialog alert = alt_bld.create(); | ||||||
|         alert.show(); |         alert.show(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     @Override | ||||||
|  |     protected void onCreate(Bundle savedInstanceState) { | ||||||
|  |         super.onCreate(savedInstanceState); | ||||||
|  |         binding = ActivityManageInstancesPeertubeBinding.inflate(getLayoutInflater()); | ||||||
|  |         View view = binding.getRoot(); | ||||||
|  |         setContentView(view); | ||||||
|  |         if (getSupportActionBar() != null) { | ||||||
|  |             getSupportActionBar().setDisplayHomeAsUpEnabled(true); | ||||||
|  |             getSupportActionBar().setDisplayShowHomeEnabled(true); | ||||||
|  |         } | ||||||
|  |         binding.loader.setVisibility(View.VISIBLE); | ||||||
|  |         binding.noAction.setVisibility(View.GONE); | ||||||
|  |         binding.lvInstances.setVisibility(View.GONE); | ||||||
|  |         binding.actionButton.setOnClickListener(v -> showRadioButtonDialogFullInstances(ManageInstancesActivity.this, getSupportFragmentManager())); | ||||||
|  |         aboutInstances = new ArrayList<>(); | ||||||
|  |         aboutInstanceAdapter = new AboutInstanceAdapter(this.aboutInstances); | ||||||
|  |         aboutInstanceAdapter.allInstancesRemoved = this; | ||||||
|  |         binding.lvInstances.setAdapter(aboutInstanceAdapter); | ||||||
|  |         LinearLayoutManager layoutManager | ||||||
|  |                 = new LinearLayoutManager(ManageInstancesActivity.this); | ||||||
|  |         binding.lvInstances.setLayoutManager(layoutManager); | ||||||
|  |         InfoInstanceVM viewModelInfoInstance = new ViewModelProvider(ManageInstancesActivity.this).get(InfoInstanceVM.class); | ||||||
|  |         viewModelInfoInstance.getInstances().observe(ManageInstancesActivity.this, this::manageVIewInfoInstance); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     private void manageVIewInfoInstance(List<InstanceData.AboutInstance> aboutInstances) { |     private void manageVIewInfoInstance(List<InstanceData.AboutInstance> aboutInstances) { | ||||||
|         binding.loader.setVisibility(View.GONE); |         binding.loader.setVisibility(View.GONE); | ||||||
|         if (aboutInstances == null || aboutInstances.size() == 0) { |         if (aboutInstances == null || aboutInstances.size() == 0) { | ||||||
|  |  | ||||||
|  | @ -127,7 +127,6 @@ import java.util.Objects; | ||||||
| import java.util.regex.Matcher; | import java.util.regex.Matcher; | ||||||
| import java.util.regex.Pattern; | import java.util.regex.Pattern; | ||||||
| 
 | 
 | ||||||
| import app.fedilab.android.BaseMainActivity; |  | ||||||
| import app.fedilab.android.R; | import app.fedilab.android.R; | ||||||
| import app.fedilab.android.activities.BasePeertubeActivity; | import app.fedilab.android.activities.BasePeertubeActivity; | ||||||
| import app.fedilab.android.databinding.ActivityPeertubeBinding; | import app.fedilab.android.databinding.ActivityPeertubeBinding; | ||||||
|  | @ -591,7 +590,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis | ||||||
|     private void playVideo() { |     private void playVideo() { | ||||||
|         if (status == null && typeOfConnection == PeertubeMainActivity.TypeOfConnection.REMOTE_ACCOUNT) { |         if (status == null && typeOfConnection == PeertubeMainActivity.TypeOfConnection.REMOTE_ACCOUNT) { | ||||||
|             app.fedilab.android.mastodon.viewmodel.mastodon.SearchVM searchVM = new ViewModelProvider(PeertubeActivity.this).get(app.fedilab.android.mastodon.viewmodel.mastodon.SearchVM.class); |             app.fedilab.android.mastodon.viewmodel.mastodon.SearchVM searchVM = new ViewModelProvider(PeertubeActivity.this).get(app.fedilab.android.mastodon.viewmodel.mastodon.SearchVM.class); | ||||||
|             searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, videoUuid, null, "statuses", false, true, false, 0, null, null, 1) |             searchVM.search(HelperInstance.getLiveInstance(PeertubeActivity.this), HelperInstance.getToken(), videoUuid, null, "statuses", false, true, false, 0, null, null, 1) | ||||||
|                     .observe(PeertubeActivity.this, results -> { |                     .observe(PeertubeActivity.this, results -> { | ||||||
|                         if (results != null && results.statuses != null && results.statuses.size() > 0) { |                         if (results != null && results.statuses != null && results.statuses.size() > 0) { | ||||||
|                             status = results.statuses.get(0); |                             status = results.statuses.get(0); | ||||||
|  | @ -1041,7 +1040,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis | ||||||
|                     } |                     } | ||||||
|                     alt_bld.setPositiveButton(R.string.yes, (dialog, id) -> { |                     alt_bld.setPositiveButton(R.string.yes, (dialog, id) -> { | ||||||
|                         if (status.reblogged) { |                         if (status.reblogged) { | ||||||
|                             statusesVM.unReblog(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id) |                             statusesVM.unReblog(HelperInstance.getLiveInstance(PeertubeActivity.this), HelperInstance.getToken(), status.id) | ||||||
|                                     .observe(PeertubeActivity.this, _status -> { |                                     .observe(PeertubeActivity.this, _status -> { | ||||||
|                                         if (_status != null) { |                                         if (_status != null) { | ||||||
|                                             status = _status; |                                             status = _status; | ||||||
|  | @ -1050,7 +1049,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis | ||||||
|                                     }); |                                     }); | ||||||
|                         } else { |                         } else { | ||||||
|                             ((SparkButton) v).playAnimation(); |                             ((SparkButton) v).playAnimation(); | ||||||
|                             statusesVM.reblog(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id, null) |                             statusesVM.reblog(HelperInstance.getLiveInstance(PeertubeActivity.this), HelperInstance.getToken(), status.id, null) | ||||||
|                                     .observe(PeertubeActivity.this, _status -> { |                                     .observe(PeertubeActivity.this, _status -> { | ||||||
|                                         if (_status != null) { |                                         if (_status != null) { | ||||||
|                                             status = _status; |                                             status = _status; | ||||||
|  | @ -1065,7 +1064,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis | ||||||
|                     alert.show(); |                     alert.show(); | ||||||
|                 } else { |                 } else { | ||||||
|                     if (status.reblogged) { |                     if (status.reblogged) { | ||||||
|                         statusesVM.unReblog(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id) |                         statusesVM.unReblog(HelperInstance.getLiveInstance(PeertubeActivity.this), HelperInstance.getToken(), status.id) | ||||||
|                                 .observe(PeertubeActivity.this, _status -> { |                                 .observe(PeertubeActivity.this, _status -> { | ||||||
|                                     if (_status != null) { |                                     if (_status != null) { | ||||||
|                                         status = _status; |                                         status = _status; | ||||||
|  | @ -1074,7 +1073,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis | ||||||
|                                 }); |                                 }); | ||||||
|                     } else { |                     } else { | ||||||
|                         ((SparkButton) v).playAnimation(); |                         ((SparkButton) v).playAnimation(); | ||||||
|                         statusesVM.reblog(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id, null) |                         statusesVM.reblog(HelperInstance.getLiveInstance(PeertubeActivity.this), HelperInstance.getToken(), status.id, null) | ||||||
|                                 .observe(PeertubeActivity.this, _status -> { |                                 .observe(PeertubeActivity.this, _status -> { | ||||||
|                                     if (_status != null) { |                                     if (_status != null) { | ||||||
|                                         status = _status; |                                         status = _status; | ||||||
|  | @ -1099,7 +1098,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis | ||||||
|                     } |                     } | ||||||
|                     alt_bld.setPositiveButton(R.string.yes, (dialog, id) -> { |                     alt_bld.setPositiveButton(R.string.yes, (dialog, id) -> { | ||||||
|                         if (status.favourited) { |                         if (status.favourited) { | ||||||
|                             statusesVM.unFavourite(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id) |                             statusesVM.unFavourite(HelperInstance.getLiveInstance(PeertubeActivity.this), HelperInstance.getToken(), status.id) | ||||||
|                                     .observe(PeertubeActivity.this, _status -> { |                                     .observe(PeertubeActivity.this, _status -> { | ||||||
|                                         if (_status != null) { |                                         if (_status != null) { | ||||||
|                                             status = _status; |                                             status = _status; | ||||||
|  | @ -1108,7 +1107,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis | ||||||
|                                     }); |                                     }); | ||||||
|                         } else { |                         } else { | ||||||
|                             ((SparkButton) v).playAnimation(); |                             ((SparkButton) v).playAnimation(); | ||||||
|                             statusesVM.favourite(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id) |                             statusesVM.favourite(HelperInstance.getLiveInstance(PeertubeActivity.this), HelperInstance.getToken(), status.id) | ||||||
|                                     .observe(PeertubeActivity.this, _status -> { |                                     .observe(PeertubeActivity.this, _status -> { | ||||||
|                                         if (_status != null) { |                                         if (_status != null) { | ||||||
|                                             status = _status; |                                             status = _status; | ||||||
|  | @ -1123,7 +1122,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis | ||||||
|                     alert.show(); |                     alert.show(); | ||||||
|                 } else { |                 } else { | ||||||
|                     if (status.favourited) { |                     if (status.favourited) { | ||||||
|                         statusesVM.unFavourite(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id) |                         statusesVM.unFavourite(HelperInstance.getLiveInstance(PeertubeActivity.this), HelperInstance.getToken(), status.id) | ||||||
|                                 .observe(PeertubeActivity.this, _status -> { |                                 .observe(PeertubeActivity.this, _status -> { | ||||||
|                                     if (_status != null) { |                                     if (_status != null) { | ||||||
|                                         status = _status; |                                         status = _status; | ||||||
|  | @ -1132,7 +1131,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis | ||||||
|                                 }); |                                 }); | ||||||
|                     } else { |                     } else { | ||||||
|                         ((SparkButton) v).playAnimation(); |                         ((SparkButton) v).playAnimation(); | ||||||
|                         statusesVM.favourite(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id) |                         statusesVM.favourite(HelperInstance.getLiveInstance(PeertubeActivity.this), HelperInstance.getToken(), status.id) | ||||||
|                                 .observe(PeertubeActivity.this, _status -> { |                                 .observe(PeertubeActivity.this, _status -> { | ||||||
|                                     if (_status != null) { |                                     if (_status != null) { | ||||||
|                                         status = _status; |                                         status = _status; | ||||||
|  | @ -1148,7 +1147,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis | ||||||
|             if (status != null) { |             if (status != null) { | ||||||
|                 StatusesVM statusesVM = new ViewModelProvider(PeertubeActivity.this).get(StatusesVM.class); |                 StatusesVM statusesVM = new ViewModelProvider(PeertubeActivity.this).get(StatusesVM.class); | ||||||
|                 if (status.bookmarked) { |                 if (status.bookmarked) { | ||||||
|                     statusesVM.unBookmark(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id) |                     statusesVM.unBookmark(HelperInstance.getLiveInstance(PeertubeActivity.this), HelperInstance.getToken(), status.id) | ||||||
|                             .observe(PeertubeActivity.this, _status -> { |                             .observe(PeertubeActivity.this, _status -> { | ||||||
|                                 if (_status != null) { |                                 if (_status != null) { | ||||||
|                                     status = _status; |                                     status = _status; | ||||||
|  | @ -1157,7 +1156,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis | ||||||
|                             }); |                             }); | ||||||
|                 } else { |                 } else { | ||||||
|                     ((SparkButton) v).playAnimation(); |                     ((SparkButton) v).playAnimation(); | ||||||
|                     statusesVM.bookmark(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, status.id) |                     statusesVM.bookmark(HelperInstance.getLiveInstance(PeertubeActivity.this), HelperInstance.getToken(), status.id) | ||||||
|                             .observe(PeertubeActivity.this, _status -> { |                             .observe(PeertubeActivity.this, _status -> { | ||||||
|                                 if (_status != null) { |                                 if (_status != null) { | ||||||
|                                     status = _status; |                                     status = _status; | ||||||
|  |  | ||||||
|  | @ -25,6 +25,7 @@ import static app.fedilab.android.BaseMainActivity.mamageNewIntent; | ||||||
| import static app.fedilab.android.BaseMainActivity.manageDrawerMenu; | import static app.fedilab.android.BaseMainActivity.manageDrawerMenu; | ||||||
| import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_ID; | import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_ID; | ||||||
| import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_INSTANCE; | import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_INSTANCE; | ||||||
|  | import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_INSTANCE_PEERTUBE_BROWSING; | ||||||
| import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_SOFTWARE; | import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_SOFTWARE; | ||||||
| import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_TOKEN; | import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_TOKEN; | ||||||
| import static app.fedilab.android.mastodon.helper.Helper.addFragment; | import static app.fedilab.android.mastodon.helper.Helper.addFragment; | ||||||
|  | @ -34,11 +35,13 @@ import static app.fedilab.android.peertube.helper.SwitchAccountHelper.switchDial | ||||||
| import android.annotation.SuppressLint; | import android.annotation.SuppressLint; | ||||||
| import android.content.Intent; | import android.content.Intent; | ||||||
| import android.content.SharedPreferences; | import android.content.SharedPreferences; | ||||||
|  | import android.database.sqlite.SQLiteDatabase; | ||||||
| import android.net.Uri; | import android.net.Uri; | ||||||
| import android.os.Build; | import android.os.Build; | ||||||
| import android.os.Bundle; | import android.os.Bundle; | ||||||
| import android.os.Handler; | import android.os.Handler; | ||||||
| import android.os.Looper; | import android.os.Looper; | ||||||
|  | import android.util.Log; | ||||||
| import android.util.TypedValue; | import android.util.TypedValue; | ||||||
| import android.view.Menu; | import android.view.Menu; | ||||||
| import android.view.MenuItem; | import android.view.MenuItem; | ||||||
|  | @ -96,7 +99,9 @@ import app.fedilab.android.peertube.fragment.FragmentLoginPickInstancePeertube; | ||||||
| import app.fedilab.android.peertube.helper.Helper; | import app.fedilab.android.peertube.helper.Helper; | ||||||
| import app.fedilab.android.peertube.helper.HelperInstance; | import app.fedilab.android.peertube.helper.HelperInstance; | ||||||
| import app.fedilab.android.peertube.services.RetrieveInfoService; | import app.fedilab.android.peertube.services.RetrieveInfoService; | ||||||
|  | import app.fedilab.android.peertube.sqlite.StoredInstanceDAO; | ||||||
| import app.fedilab.android.peertube.viewmodel.TimelineVM; | import app.fedilab.android.peertube.viewmodel.TimelineVM; | ||||||
|  | import app.fedilab.android.sqlite.Sqlite; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| public class PeertubeMainActivity extends PeertubeBaseMainActivity { | public class PeertubeMainActivity extends PeertubeBaseMainActivity { | ||||||
|  | @ -165,13 +170,35 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity { | ||||||
|             if (extras != null && extras.containsKey(app.fedilab.android.mastodon.helper.Helper.ARG_PEERTUBE_NAV_REMOTE)) { |             if (extras != null && extras.containsKey(app.fedilab.android.mastodon.helper.Helper.ARG_PEERTUBE_NAV_REMOTE)) { | ||||||
|                 if (extras.getBoolean(app.fedilab.android.mastodon.helper.Helper.ARG_PEERTUBE_NAV_REMOTE)) { |                 if (extras.getBoolean(app.fedilab.android.mastodon.helper.Helper.ARG_PEERTUBE_NAV_REMOTE)) { | ||||||
|                     typeOfConnection = PeertubeMainActivity.TypeOfConnection.REMOTE_ACCOUNT; |                     typeOfConnection = PeertubeMainActivity.TypeOfConnection.REMOTE_ACCOUNT; | ||||||
|  |                     intentActvity.removeExtra(app.fedilab.android.mastodon.helper.Helper.ARG_PEERTUBE_NAV_REMOTE); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |         SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(PeertubeMainActivity.this); | ||||||
|  | 
 | ||||||
|  |         if (typeOfConnection == TypeOfConnection.REMOTE_ACCOUNT) { | ||||||
|  |             String defaultInstance = sharedpreferences.getString(PREF_USER_INSTANCE_PEERTUBE_BROWSING, null); | ||||||
|  |             Log.v(app.fedilab.android.mastodon.helper.Helper.TAG, "defaultInstance-->: " + defaultInstance); | ||||||
|  |             if (defaultInstance == null) { | ||||||
|  |                 getSupportFragmentManager().setFragmentResultListener(PICK_INSTANCE, PeertubeMainActivity.this, (requestKey, result) -> { | ||||||
|  |                     new Thread(() -> { | ||||||
|  |                         String newInstance = result.getString(INSTANCE_ADDRESS); | ||||||
|  |                         InstanceData.AboutInstance aboutInstance = new RetrofitPeertubeAPI(PeertubeMainActivity.this, newInstance, null).getAboutInstance(); | ||||||
|  |                         SQLiteDatabase db = Sqlite.getInstance(PeertubeMainActivity.this, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); | ||||||
|  |                         new StoredInstanceDAO(PeertubeMainActivity.this, db).insertInstance(aboutInstance, newInstance); | ||||||
|  |                     }).start(); | ||||||
|  |                     getSupportFragmentManager().clearFragmentResultListener(PICK_INSTANCE); | ||||||
|  |                 }); | ||||||
|  |                 addFragment( | ||||||
|  |                         getSupportFragmentManager(), android.R.id.content, new FragmentLoginPickInstancePeertube(), | ||||||
|  |                         null, null, FragmentLoginPickInstancePeertube.class.getName()); | ||||||
|  |             } | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         Toolbar toolbar = findViewById(R.id.toolbar); |         Toolbar toolbar = findViewById(R.id.toolbar); | ||||||
|         setSupportActionBar(toolbar); |         setSupportActionBar(toolbar); | ||||||
| 
 | 
 | ||||||
|         SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(PeertubeMainActivity.this); |  | ||||||
| 
 | 
 | ||||||
|         badgeCount = 0; |         badgeCount = 0; | ||||||
|         headerMenuOpen = false; |         headerMenuOpen = false; | ||||||
|  | @ -207,6 +234,8 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity { | ||||||
| 
 | 
 | ||||||
|         NavHeaderMainBinding headerMainBinding = NavHeaderMainBinding.inflate(getLayoutInflater()); |         NavHeaderMainBinding headerMainBinding = NavHeaderMainBinding.inflate(getLayoutInflater()); | ||||||
|         currentAccount = null; |         currentAccount = null; | ||||||
|  |         if (Helper.isLoggedIn()) { | ||||||
|  | 
 | ||||||
|             new Thread(() -> { |             new Thread(() -> { | ||||||
|                 try { |                 try { | ||||||
|                     if (currentToken == null) { |                     if (currentToken == null) { | ||||||
|  | @ -278,30 +307,29 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity { | ||||||
|                             manageDrawerMenu(PeertubeMainActivity.this, binding.drawerNavView, headerMainBinding); |                             manageDrawerMenu(PeertubeMainActivity.this, binding.drawerNavView, headerMainBinding); | ||||||
|                         }); |                         }); | ||||||
|                     } |                     } | ||||||
| 
 |  | ||||||
|                 if (Helper.isLoggedIn()) { |  | ||||||
|                     binding.navView.inflateMenu(R.menu.bottom_nav_menu_connected_peertube); |                     binding.navView.inflateMenu(R.menu.bottom_nav_menu_connected_peertube); | ||||||
|                     refreshToken(); |                     refreshToken(); | ||||||
| 
 | 
 | ||||||
|                 } else { |  | ||||||
|                     binding.navView.inflateMenu(R.menu.bottom_nav_menu); |  | ||||||
|                 } |  | ||||||
|                 }; |                 }; | ||||||
|                 mainHandler.post(myRunnable); |                 mainHandler.post(myRunnable); | ||||||
|             }).start(); |             }).start(); | ||||||
|  |         } else { | ||||||
|  |             binding.navView.inflateMenu(R.menu.bottom_nav_menu_peertube); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         headerMainBinding.instanceInfo.setVisibility(View.GONE); |         headerMainBinding.instanceInfo.setVisibility(View.GONE); | ||||||
| 
 | 
 | ||||||
|         headerMainBinding.headerOptionInfo.setOnClickListener(v -> headerOptionInfoClick(PeertubeMainActivity.this, headerMainBinding, getSupportFragmentManager())); |         headerMainBinding.headerOptionInfo.setOnClickListener(v -> headerOptionInfoClick(PeertubeMainActivity.this, headerMainBinding, getSupportFragmentManager())); | ||||||
| 
 | 
 | ||||||
|  |         if (Helper.isLoggedIn()) { | ||||||
|             binding.drawerNavView.addHeaderView(headerMainBinding.getRoot()); |             binding.drawerNavView.addHeaderView(headerMainBinding.getRoot()); | ||||||
| 
 |  | ||||||
|             binding.drawerNavView.setNavigationItemSelectedListener(item -> { |             binding.drawerNavView.setNavigationItemSelectedListener(item -> { | ||||||
|                 if (item.getItemId() == R.id.action_settings) { |                 if (item.getItemId() == R.id.action_settings) { | ||||||
|                     Intent intent = new Intent(PeertubeMainActivity.this, SettingsActivity.class); |                     Intent intent = new Intent(PeertubeMainActivity.this, SettingsActivity.class); | ||||||
|                     startActivity(intent); |                     startActivity(intent); | ||||||
|                 } else if (item.getItemId() == R.id.action_account) { |                 } else if (item.getItemId() == R.id.action_account) { | ||||||
|                     Intent intent; |                     Intent intent; | ||||||
|                 if (typeOfConnection == TypeOfConnection.SURFING) { |                     if (typeOfConnection == TypeOfConnection.SURFING || typeOfConnection == TypeOfConnection.REMOTE_ACCOUNT) { | ||||||
|                         switchDialog(PeertubeMainActivity.this, false); |                         switchDialog(PeertubeMainActivity.this, false); | ||||||
|                     } else { |                     } else { | ||||||
|                         if (Helper.canMakeAction()) { |                         if (Helper.canMakeAction()) { | ||||||
|  | @ -349,6 +377,10 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity { | ||||||
|                 binding.drawerLayout.close(); |                 binding.drawerLayout.close(); | ||||||
|                 return false; |                 return false; | ||||||
|             }); |             }); | ||||||
|  |         } else { | ||||||
|  |             binding.drawerNavView.setVisibility(View.GONE); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
|         overviewFragment = new DisplayOverviewFragment(); |         overviewFragment = new DisplayOverviewFragment(); | ||||||
|         if (!Helper.isLoggedIn()) { |         if (!Helper.isLoggedIn()) { | ||||||
|  | @ -546,6 +578,7 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity { | ||||||
|                                 case NORMAL: |                                 case NORMAL: | ||||||
|                                     accountItem.setVisible(true); |                                     accountItem.setVisible(true); | ||||||
|                                     break; |                                     break; | ||||||
|  |                                 case REMOTE_ACCOUNT: | ||||||
|                                 case SURFING: |                                 case SURFING: | ||||||
|                                     accountItem.setVisible(false); |                                     accountItem.setVisible(false); | ||||||
|                                     break; |                                     break; | ||||||
|  | @ -601,7 +634,6 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity { | ||||||
| 
 | 
 | ||||||
|         MenuItem incognitoItem = menu.findItem(R.id.action_incognito); |         MenuItem incognitoItem = menu.findItem(R.id.action_incognito); | ||||||
|         switch (typeOfConnection) { |         switch (typeOfConnection) { | ||||||
|             case REMOTE_ACCOUNT: |  | ||||||
|             case NORMAL: |             case NORMAL: | ||||||
|                 if (Helper.isLoggedIn()) { |                 if (Helper.isLoggedIn()) { | ||||||
|                     incognitoItem.setVisible(true); |                     incognitoItem.setVisible(true); | ||||||
|  | @ -612,6 +644,7 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity { | ||||||
|                     incognitoItem.setVisible(false); |                     incognitoItem.setVisible(false); | ||||||
|                 } |                 } | ||||||
|                 break; |                 break; | ||||||
|  |             case REMOTE_ACCOUNT: | ||||||
|             case SURFING: |             case SURFING: | ||||||
|                 incognitoItem.setVisible(false); |                 incognitoItem.setVisible(false); | ||||||
|                 break; |                 break; | ||||||
|  |  | ||||||
|  | @ -15,12 +15,18 @@ package app.fedilab.android.peertube.fragment; | ||||||
|  * see <http://www.gnu.org/licenses>. */ |  * see <http://www.gnu.org/licenses>. */ | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_INSTANCE_PEERTUBE_BROWSING; | ||||||
| import static app.fedilab.android.peertube.activities.PeertubeMainActivity.INSTANCE_ADDRESS; | import static app.fedilab.android.peertube.activities.PeertubeMainActivity.INSTANCE_ADDRESS; | ||||||
|  | import static app.fedilab.android.peertube.activities.PeertubeMainActivity.typeOfConnection; | ||||||
| import static app.fedilab.android.peertube.helper.Helper.peertubeInformation; | import static app.fedilab.android.peertube.helper.Helper.peertubeInformation; | ||||||
| 
 | 
 | ||||||
|  | import android.content.SharedPreferences; | ||||||
| import android.os.Bundle; | import android.os.Bundle; | ||||||
|  | import android.os.Handler; | ||||||
|  | import android.os.Looper; | ||||||
| import android.text.SpannableStringBuilder; | import android.text.SpannableStringBuilder; | ||||||
| import android.text.Spanned; | import android.text.Spanned; | ||||||
|  | import android.util.Log; | ||||||
| import android.view.LayoutInflater; | import android.view.LayoutInflater; | ||||||
| import android.view.View; | import android.view.View; | ||||||
| import android.view.ViewGroup; | import android.view.ViewGroup; | ||||||
|  | @ -34,6 +40,7 @@ import androidx.annotation.Nullable; | ||||||
| import androidx.appcompat.app.AlertDialog; | import androidx.appcompat.app.AlertDialog; | ||||||
| import androidx.fragment.app.Fragment; | import androidx.fragment.app.Fragment; | ||||||
| import androidx.lifecycle.ViewModelProvider; | import androidx.lifecycle.ViewModelProvider; | ||||||
|  | import androidx.preference.PreferenceManager; | ||||||
| import androidx.recyclerview.widget.LinearLayoutManager; | import androidx.recyclerview.widget.LinearLayoutManager; | ||||||
| 
 | 
 | ||||||
| import com.google.android.material.dialog.MaterialAlertDialogBuilder; | import com.google.android.material.dialog.MaterialAlertDialogBuilder; | ||||||
|  | @ -47,9 +54,12 @@ import java.util.Map; | ||||||
| import app.fedilab.android.R; | import app.fedilab.android.R; | ||||||
| import app.fedilab.android.databinding.FragmentLoginPickInstancePeertubeBinding; | import app.fedilab.android.databinding.FragmentLoginPickInstancePeertubeBinding; | ||||||
| import app.fedilab.android.mastodon.helper.Helper; | import app.fedilab.android.mastodon.helper.Helper; | ||||||
|  | import app.fedilab.android.peertube.activities.PeertubeMainActivity; | ||||||
| import app.fedilab.android.peertube.client.APIResponse; | import app.fedilab.android.peertube.client.APIResponse; | ||||||
|  | import app.fedilab.android.peertube.client.RetrofitPeertubeAPI; | ||||||
| import app.fedilab.android.peertube.client.data.InstanceData; | import app.fedilab.android.peertube.client.data.InstanceData; | ||||||
| import app.fedilab.android.peertube.client.entities.InstanceParams; | import app.fedilab.android.peertube.client.entities.InstanceParams; | ||||||
|  | import app.fedilab.android.peertube.client.entities.PeertubeInformation; | ||||||
| import app.fedilab.android.peertube.drawer.InstanceAdapter; | import app.fedilab.android.peertube.drawer.InstanceAdapter; | ||||||
| import app.fedilab.android.peertube.helper.RoundedBackgroundSpan; | import app.fedilab.android.peertube.helper.RoundedBackgroundSpan; | ||||||
| import app.fedilab.android.peertube.viewmodel.InstancesVM; | import app.fedilab.android.peertube.viewmodel.InstancesVM; | ||||||
|  | @ -74,6 +84,36 @@ public class FragmentLoginPickInstancePeertube extends Fragment implements Insta | ||||||
|     public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { |     public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | ||||||
|         binding = FragmentLoginPickInstancePeertubeBinding.inflate(inflater, container, false); |         binding = FragmentLoginPickInstancePeertubeBinding.inflate(inflater, container, false); | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  |         if (peertubeInformation == null || peertubeInformation.getLanguages() == null) { | ||||||
|  |             new Thread(() -> { | ||||||
|  |                 peertubeInformation = new PeertubeInformation(); | ||||||
|  |                 peertubeInformation.setCategories(new LinkedHashMap<>()); | ||||||
|  |                 peertubeInformation.setLanguages(new LinkedHashMap<>()); | ||||||
|  |                 peertubeInformation.setLicences(new LinkedHashMap<>()); | ||||||
|  |                 peertubeInformation.setPrivacies(new LinkedHashMap<>()); | ||||||
|  |                 peertubeInformation.setPlaylistPrivacies(new LinkedHashMap<>()); | ||||||
|  |                 peertubeInformation.setTranslations(new LinkedHashMap<>()); | ||||||
|  |                 peertubeInformation = new RetrofitPeertubeAPI(requireActivity()).getPeertubeInformation(); | ||||||
|  |                 Handler mainHandler = new Handler(Looper.getMainLooper()); | ||||||
|  |                 Runnable myRunnable = () -> { | ||||||
|  |                     if (peertubeInformation == null || peertubeInformation.getLanguages() == null) { | ||||||
|  |                         Toasty.error(requireActivity(), getString(R.string.toast_error), Toasty.LENGTH_SHORT).show(); | ||||||
|  |                     } else { | ||||||
|  |                         initializeView(); | ||||||
|  |                     } | ||||||
|  |                 }; | ||||||
|  |                 mainHandler.post(myRunnable); | ||||||
|  | 
 | ||||||
|  |             }).start(); | ||||||
|  |         } else { | ||||||
|  |             initializeView(); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return binding.getRoot(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private void initializeView() { | ||||||
|         binding.loader.setVisibility(View.VISIBLE); |         binding.loader.setVisibility(View.VISIBLE); | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -100,7 +140,6 @@ public class FragmentLoginPickInstancePeertube extends Fragment implements Insta | ||||||
| 
 | 
 | ||||||
|             } |             } | ||||||
|         }); |         }); | ||||||
| 
 |  | ||||||
|         if (peertubeInformation != null && peertubeInformation.getLanguages() != null) { |         if (peertubeInformation != null && peertubeInformation.getLanguages() != null) { | ||||||
|             LinkedHashMap<String, String> languages = new LinkedHashMap<>(peertubeInformation.getLanguages()); |             LinkedHashMap<String, String> languages = new LinkedHashMap<>(peertubeInformation.getLanguages()); | ||||||
|             checkedItemsLanguage = new boolean[languages.size()]; |             checkedItemsLanguage = new boolean[languages.size()]; | ||||||
|  | @ -238,11 +277,9 @@ public class FragmentLoginPickInstancePeertube extends Fragment implements Insta | ||||||
|         instanceParams = new InstanceParams(); |         instanceParams = new InstanceParams(); | ||||||
|         instanceParams.setNsfwPolicy(channelSensitive[1]); |         instanceParams.setNsfwPolicy(channelSensitive[1]); | ||||||
|         viewModel.getInstances(instanceParams).observe(getViewLifecycleOwner(), this::manageVIewInstance); |         viewModel.getInstances(instanceParams).observe(getViewLifecycleOwner(), this::manageVIewInstance); | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|         return binding.getRoot(); |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|     public void manageVIewInstance(APIResponse apiResponse) { |     public void manageVIewInstance(APIResponse apiResponse) { | ||||||
|         binding.loader.setVisibility(View.GONE); |         binding.loader.setVisibility(View.GONE); | ||||||
|         if (apiResponse.getError() != null) { |         if (apiResponse.getError() != null) { | ||||||
|  | @ -265,6 +302,15 @@ public class FragmentLoginPickInstancePeertube extends Fragment implements Insta | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public void instance(String instance) { |     public void instance(String instance) { | ||||||
|  |         if (typeOfConnection == PeertubeMainActivity.TypeOfConnection.REMOTE_ACCOUNT) { | ||||||
|  |             final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); | ||||||
|  |             SharedPreferences.Editor editor = sharedpreferences.edit(); | ||||||
|  |             editor.putString(PREF_USER_INSTANCE_PEERTUBE_BROWSING, instance); | ||||||
|  |             editor.commit(); | ||||||
|  |             Log.v(Helper.TAG, "-->: " + instance); | ||||||
|  |             requireActivity().recreate(); | ||||||
|  | 
 | ||||||
|  |         } else { | ||||||
|             Bundle bundle = new Bundle(); |             Bundle bundle = new Bundle(); | ||||||
|             bundle.putString(INSTANCE_ADDRESS, instance); |             bundle.putString(INSTANCE_ADDRESS, instance); | ||||||
|             Helper.addFragment( |             Helper.addFragment( | ||||||
|  | @ -272,3 +318,4 @@ public class FragmentLoginPickInstancePeertube extends Fragment implements Insta | ||||||
|                     bundle, null, PeertubeRegisterFragment.class.getName()); |                     bundle, null, PeertubeRegisterFragment.class.getName()); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -14,13 +14,18 @@ package app.fedilab.android.peertube.helper; | ||||||
|  * You should have received a copy of the GNU General Public License along with Fedilab; if not, |  * You should have received a copy of the GNU General Public License along with Fedilab; if not, | ||||||
|  * see <http://www.gnu.org/licenses>. */ |  * see <http://www.gnu.org/licenses>. */ | ||||||
| 
 | 
 | ||||||
|  | import static app.fedilab.android.BaseMainActivity.currentToken; | ||||||
| import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_INSTANCE; | import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_INSTANCE; | ||||||
|  | import static app.fedilab.android.mastodon.helper.Helper.PREF_USER_INSTANCE_PEERTUBE_BROWSING; | ||||||
|  | import static app.fedilab.android.peertube.activities.PeertubeMainActivity.typeOfConnection; | ||||||
| 
 | 
 | ||||||
| import android.content.Context; | import android.content.Context; | ||||||
| import android.content.SharedPreferences; | import android.content.SharedPreferences; | ||||||
| 
 | 
 | ||||||
| import androidx.preference.PreferenceManager; | import androidx.preference.PreferenceManager; | ||||||
| 
 | 
 | ||||||
|  | import app.fedilab.android.peertube.activities.PeertubeMainActivity; | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| public class HelperInstance { | public class HelperInstance { | ||||||
| 
 | 
 | ||||||
|  | @ -33,7 +38,19 @@ public class HelperInstance { | ||||||
|      */ |      */ | ||||||
|     public static String getLiveInstance(Context context) { |     public static String getLiveInstance(Context context) { | ||||||
|         final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); |         final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); | ||||||
|  |         if (typeOfConnection == PeertubeMainActivity.TypeOfConnection.REMOTE_ACCOUNT) { | ||||||
|  |             return sharedpreferences.getString(PREF_USER_INSTANCE_PEERTUBE_BROWSING, null); | ||||||
|  |         } else { | ||||||
|             return sharedpreferences.getString(PREF_USER_INSTANCE, null); |             return sharedpreferences.getString(PREF_USER_INSTANCE, null); | ||||||
|         } |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public static String getToken() { | ||||||
|  |         if (typeOfConnection == PeertubeMainActivity.TypeOfConnection.REMOTE_ACCOUNT) { | ||||||
|  |             return null; | ||||||
|  |         } else { | ||||||
|  |             return currentToken; | ||||||
|  |         } | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -68,7 +68,10 @@ | ||||||
|         android:layout_height="wrap_content" |         android:layout_height="wrap_content" | ||||||
|         android:layout_alignParentEnd="true" |         android:layout_alignParentEnd="true" | ||||||
|         android:layout_alignParentBottom="true" |         android:layout_alignParentBottom="true" | ||||||
|         android:layout_margin="@dimen/fab_margin" |         android:layout_marginStart="@dimen/fab_margin" | ||||||
|  |         android:layout_marginTop="@dimen/fab_margin" | ||||||
|  |         android:layout_marginEnd="@dimen/fab_margin" | ||||||
|  |         android:layout_marginBottom="@dimen/fab_margin" | ||||||
|         android:contentDescription="@string/instances_picker" |         android:contentDescription="@string/instances_picker" | ||||||
|         android:src="@drawable/ic_baseline_add_24" |         android:src="@drawable/ic_baseline_add_24" | ||||||
|         android:tint="@android:color/white" /> |         android:tint="@android:color/white" /> | ||||||
|  |  | ||||||
|  | @ -18,6 +18,7 @@ | ||||||
|     xmlns:app="http://schemas.android.com/apk/res-auto" |     xmlns:app="http://schemas.android.com/apk/res-auto" | ||||||
|     android:layout_width="match_parent" |     android:layout_width="match_parent" | ||||||
|     android:layout_height="match_parent" |     android:layout_height="match_parent" | ||||||
|  |     android:layout_marginTop="@dimen/fab_margin" | ||||||
|     android:background="?android:windowBackground"> |     android:background="?android:windowBackground"> | ||||||
| 
 | 
 | ||||||
|     <com.google.android.material.card.MaterialCardView |     <com.google.android.material.card.MaterialCardView | ||||||
|  | @ -42,6 +43,7 @@ | ||||||
|                 android:gravity="center" |                 android:gravity="center" | ||||||
|                 android:text="@string/pickup_categories" |                 android:text="@string/pickup_categories" | ||||||
|                 app:layout_constraintStart_toStartOf="parent" |                 app:layout_constraintStart_toStartOf="parent" | ||||||
|  |                 app:layout_constraintEnd_toStartOf="@+id/pickup_languages" | ||||||
|                 app:layout_constraintTop_toTopOf="parent" /> |                 app:layout_constraintTop_toTopOf="parent" /> | ||||||
| 
 | 
 | ||||||
|             <com.google.android.material.button.MaterialButton |             <com.google.android.material.button.MaterialButton | ||||||
|  | @ -52,6 +54,7 @@ | ||||||
|                 android:gravity="center" |                 android:gravity="center" | ||||||
|                 android:text="@string/pickup_languages" |                 android:text="@string/pickup_languages" | ||||||
|                 app:layout_constraintStart_toEndOf="@id/pickup_categories" |                 app:layout_constraintStart_toEndOf="@id/pickup_categories" | ||||||
|  |                 app:layout_constraintEnd_toEndOf="parent" | ||||||
|                 app:layout_constraintTop_toTopOf="parent" /> |                 app:layout_constraintTop_toTopOf="parent" /> | ||||||
| 
 | 
 | ||||||
|             <TextView |             <TextView | ||||||
|  | @ -121,6 +124,7 @@ | ||||||
|         android:layout_height="0dp" |         android:layout_height="0dp" | ||||||
|         android:layout_marginTop="10dp" |         android:layout_marginTop="10dp" | ||||||
|         android:orientation="vertical" |         android:orientation="vertical" | ||||||
|  |         android:padding="12dp" | ||||||
|         app:layout_constraintBottom_toBottomOf="parent" |         app:layout_constraintBottom_toBottomOf="parent" | ||||||
|         app:layout_constraintEnd_toEndOf="parent" |         app:layout_constraintEnd_toEndOf="parent" | ||||||
|         app:layout_constraintStart_toStartOf="parent" |         app:layout_constraintStart_toStartOf="parent" | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue