Search in sources :

Example 1 with AllContentFragment

use of com.odysee.app.ui.findcontent.AllContentFragment in project odysee-android by OdyseeTeam.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.AppTheme_NoActionBar);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    if (Build.VERSION.SDK_INT < 31) {
        findViewById(R.id.root).setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
        findViewById(R.id.launch_splash).setVisibility(View.VISIBLE);
    } else {
        findViewById(R.id.root).getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {

            @Override
            public boolean onPreDraw() {
                // Check if the initial data is ready.
                if (readyToDraw) {
                    // The content is ready; start drawing.
                    findViewById(R.id.root).getViewTreeObserver().removeOnPreDrawListener(this);
                    return true;
                } else {
                    // The content is not ready; suspend.
                    return false;
                }
            }
        });
    }
    instance = this;
    // workaround to fix dark theme because https://issuetracker.google.com/issues/37124582
    try {
        new WebView(this);
    } catch (Exception ex) {
    // pass (don't fail initialization on some _weird_ device implementations)
    }
    // Set app theme depending on Night mode
    if (getDarkModeAppSetting().equals(APP_SETTING_DARK_MODE_NIGHT)) {
        AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
    } else if (getDarkModeAppSetting().equals(APP_SETTING_DARK_MODE_NOTNIGHT)) {
        AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
    } else {
        AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
    }
    initKeyStore();
    loadAuthToken();
    // Change status bar text color depending on Night mode when app is running
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1 && Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
        if (!getDarkModeAppSetting().equals(APP_SETTING_DARK_MODE_NIGHT) && AppCompatDelegate.getDefaultNightMode() != AppCompatDelegate.MODE_NIGHT_YES) {
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }
    } else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
        int defaultNight = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
        if (getDarkModeAppSetting().equals(APP_SETTING_DARK_MODE_NOTNIGHT) || (getDarkModeAppSetting().equals(APP_SETTING_DARK_MODE_SYSTEM) && defaultNight == Configuration.UI_MODE_NIGHT_NO)) {
            if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {
                getWindow().getDecorView().getWindowInsetsController().setSystemBarsAppearance(WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS, WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS);
            } else {
                getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
            }
        }
    }
    activityResultLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback<ActivityResult>() {

        @Override
        public void onActivityResult(ActivityResult result) {
            if (result.getResultCode() == Activity.RESULT_OK) {
                // first run completed or skipped
                checkFirstYouTubeSync();
                return;
            }
            if (result.getResultCode() == Activity.RESULT_CANCELED) {
                // back button pressed, so it was cancelled
                finish();
            }
        }
    });
    initSpecialRouteMap();
    LbryAnalytics.init(this);
    FirebaseMessagingToken.getFirebaseMessagingToken(new FirebaseMessagingToken.GetTokenListener() {

        @Override
        public void onComplete(String token) {
            firebaseMessagingToken = token;
        }
    });
    // create player notification channel
    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel channel = new NotificationChannel(PLAYER_NOTIFICATION_CHANNEL_ID, "Odysee Player", NotificationManager.IMPORTANCE_LOW);
        channel.setDescription("Odysee player notification channel");
        channel.setShowBadge(false);
        notificationManager.createNotificationChannel(channel);
    }
    dbHelper = new DatabaseHelper(this);
    Executors.newSingleThreadExecutor().execute(new Runnable() {

        @Override
        public void run() {
            SQLiteDatabase db = dbHelper.getWritableDatabase();
            if (db != null) {
                DatabaseHelper.checkAndCreateBuiltinPlaylists(dbHelper.getWritableDatabase());
            }
        }
    });
    checkNotificationOpenIntent(getIntent());
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    updateMiniPlayerMargins(true);
    OnBackPressedCallback callback = new OnBackPressedCallback(true) {

        /* enabled by default */
        @Override
        public void handleOnBackPressed() {
            moveTaskToBack(true);
        }
    };
    getOnBackPressedDispatcher().addCallback(this, callback);
    // setup the purchased checker in main activity (to handle cases where the verification purchase flow may have been interrupted)
    purchasedChecker = new PurchasedChecker(this, MainActivity.this);
    purchasedChecker.createBillingClientAndEstablishConnection();
    playerNotificationManager = new PlayerNotificationManager.Builder(this, PLAYBACK_NOTIFICATION_ID, PLAYER_NOTIFICATION_CHANNEL_ID, new PlayerNotificationDescriptionAdapter()).build();
    // TODO: Check Google Play Services availability
    // castContext = CastContext.getSharedInstance(this);
    ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.content_main), new OnApplyWindowInsetsListener() {

        @Override
        public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
            ViewCompat.onApplyWindowInsets(findViewById(R.id.url_suggestions_container), insets.replaceSystemWindowInsets(0, 0, 0, insets.getSystemWindowInsetBottom()));
            return ViewCompat.onApplyWindowInsets(v, insets.replaceSystemWindowInsets(0, 0, 0, insets.getSystemWindowInsetBottom()));
        }
    });
    // register receivers
    registerRequestsReceiver();
    registerUAReceiver();
    // setup uri bar
    // setupUriBar();
    initNotificationsPage();
    loadUnseenNotificationsCount();
    // other
    pendingSyncSetQueue = new ArrayList<>();
    cameraPermissionListeners = new ArrayList<>();
    downloadActionListeners = new ArrayList<>();
    fetchChannelsListeners = new ArrayList<>();
    fetchClaimsListeners = new ArrayList<>();
    filePickerListeners = new ArrayList<>();
    pipModeListeners = new ArrayList<>();
    screenOrientationListeners = new ArrayList<>();
    storagePermissionListeners = new ArrayList<>();
    walletBalanceListeners = new ArrayList<>();
    SharedPreferences sharedPreferences = getSharedPreferences("lbry_shared_preferences", MODE_PRIVATE);
    SharedPreferences.Editor sharedPreferencesEditor = sharedPreferences.edit();
    if (sharedPreferences.getString("lbry_installation_id", "").equals("")) {
        Lbry.INSTALLATION_ID = Lbry.generateId();
        sharedPreferencesEditor.putString("lbry_installation_id", Lbry.INSTALLATION_ID);
        sharedPreferencesEditor.commit();
    }
    // for privacy concerns.
    if (sharedPreferences.contains("auth_token")) {
        sharedPreferencesEditor.remove("auth_token").apply();
    }
    SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    SharedPreferences.Editor defaultSharedPreferencesEditor = defaultSharedPreferences.edit();
    if (defaultSharedPreferences.contains("com.odysee.app.Preference.AuthToken")) {
        defaultSharedPreferencesEditor.remove("com.odysee.app.Preference.AuthToken").apply();
    }
    // Create Fragment instances here so they are not recreated when selected on the bottom navigation bar
    Fragment homeFragment = new AllContentFragment();
    Fragment followingFragment = new FollowingFragment();
    Fragment walletFragment = new WalletFragment();
    Fragment libraryFragment = new LibraryFragment();
    FragmentManager fragmentManager = getSupportFragmentManager();
    fragmentManager.addOnBackStackChangedListener(backStackChangedListener);
    BottomNavigationView bottomNavigation = findViewById(R.id.bottom_navigation);
    bottomNavigation.setOnItemSelectedListener(new NavigationBarView.OnItemSelectedListener() {

        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            Fragment selectedFragment;
            String fragmentTag;
            if (!isSignedIn() && item.getItemId() != R.id.action_home_menu) {
                simpleSignIn(item.getItemId());
                return false;
            }
            switch(item.getItemId()) {
                case R.id.action_home_menu:
                default:
                    selectedFragment = homeFragment;
                    fragmentTag = "HOME";
                    break;
                case R.id.action_following_menu:
                    selectedFragment = followingFragment;
                    fragmentTag = "FOLLOWING";
                    break;
                case R.id.action_wallet_menu:
                    selectedFragment = walletFragment;
                    fragmentTag = "WALLET";
                    break;
                case R.id.action_library_menu:
                    selectedFragment = libraryFragment;
                    fragmentTag = "LIBRARY";
                    break;
            }
            getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container_main_activity, selectedFragment, fragmentTag).commit();
            return true;
        }
    });
    bottomNavigation.setSelectedItemId(R.id.action_home_menu);
    findViewById(R.id.brand).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            bottomNavigation.setSelectedItemId(R.id.action_home_menu);
        }
    });
    findViewById(R.id.wallet_balance_container).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            hideNotifications();
            bottomNavigation.setSelectedItemId(R.id.action_wallet_menu);
        }
    });
    findViewById(R.id.upload_button).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            // Hide bottom navigation
            // Hide main bar
            // Show PublishFragment.class
            // hideNotifications(); // Avoid showing Notifications fragment when clicking Publish when Notification panel is opened
            // fragmentManager.beginTransaction().replace(R.id.main_activity_other_fragment, new PublishFragment(), "PUBLISH").addToBackStack("publish_claim").commit();
            // findViewById(R.id.main_activity_other_fragment).setVisibility(View.VISIBLE);
            // findViewById(R.id.fragment_container_main_activity).setVisibility(View.GONE);
            // hideActionBar();
            clearPlayingPlayer();
            startActivity(new Intent(view.getContext(), ComingSoon.class));
        }
    });
    findViewById(R.id.search_button).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            // Enter Search Mode
            hideNotifications();
            hideBottomNavigation();
            switchToolbarForSearch(true);
            findViewById(R.id.fragment_container_main_activity).setVisibility(View.GONE);
            if (!isSearchUIActive()) {
                try {
                    SearchFragment searchFragment = SearchFragment.class.newInstance();
                    getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container_search, searchFragment, "SEARCH").commit();
                    currentDisplayFragment = searchFragment;
                    findViewById(R.id.fragment_container_search).setVisibility(View.VISIBLE);
                    findViewById(R.id.search_query_text).requestFocus();
                    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.showSoftInput(findViewById(R.id.search_query_text), InputMethodManager.SHOW_FORCED);
                } catch (IllegalAccessException | InstantiationException e) {
                    e.printStackTrace();
                }
            } else {
                EditText queryText = findViewById(R.id.search_query_text);
                // hide keyboard
                InputMethodManager inputMethodManager = (InputMethodManager) queryText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                inputMethodManager.hideSoftInputFromWindow(queryText.getWindowToken(), 0);
                findViewById(R.id.fragment_container_search).setVisibility(View.VISIBLE);
                String query = queryText.getText().toString();
                SearchFragment searchFragment = (SearchFragment) getSupportFragmentManager().findFragmentByTag("SEARCH");
                if (searchFragment != null) {
                    searchFragment.search(query, 0);
                }
            }
        }
    });
    ((EditText) findViewById(R.id.search_query_text)).addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            Context context = getApplicationContext();
            if (context != null) {
                SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
                autoSearchEnabled = sp.getBoolean("com.odysee.app.preference.userinterface.Autosearch", false);
            }
            if (autoSearchEnabled) {
                if (searchWorker == null) {
                    searchWorker = Executors.newSingleThreadScheduledExecutor();
                }
                // Let it finish otherwise, as it will be re-scheduled on aftertextChanged()
                if (scheduledSearchFuture != null && !scheduledSearchFuture.isCancelled()) {
                    scheduledSearchFuture.cancel(false);
                }
            }
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (autoSearchEnabled) {
                if (!s.toString().equals("")) {
                    Runnable runnable = new Runnable() {

                        public void run() {
                            runOnUiThread(new Runnable() {

                                @Override
                                public void run() {
                                    EditText queryText = findViewById(R.id.search_query_text);
                                    findViewById(R.id.fragment_container_search).setVisibility(View.VISIBLE);
                                    String query = queryText.getText().toString();
                                    SearchFragment searchFragment = (SearchFragment) getSupportFragmentManager().findFragmentByTag("SEARCH");
                                    if (searchFragment != null) {
                                        searchFragment.search(query, 0);
                                    }
                                }
                            });
                        }
                    };
                    scheduledSearchFuture = searchWorker.schedule(runnable, 500, TimeUnit.MILLISECONDS);
                } else {
                    SearchFragment searchFragment = (SearchFragment) getSupportFragmentManager().findFragmentByTag("SEARCH");
                    if (searchFragment != null) {
                        searchFragment.search("", 0);
                    }
                }
            }
        }
    });
    ((EditText) findViewById(R.id.search_query_text)).setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (i == EditorInfo.IME_ACTION_SEARCH) {
                findViewById(R.id.search_button).callOnClick();
                return true;
            }
            return false;
        }
    });
    findViewById(R.id.search_close_button).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            EditText queryText = findViewById(R.id.search_query_text);
            InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            inputMethodManager.hideSoftInputFromWindow(queryText.getWindowToken(), 0);
            Fragment searchFragment = getSupportFragmentManager().findFragmentByTag("SEARCH");
            if (searchFragment != null) {
                getSupportFragmentManager().beginTransaction().remove(searchFragment).commit();
            }
            ((EditText) findViewById(R.id.search_query_text)).setText("");
            showBottomNavigation();
            switchToolbarForSearch(false);
            // On tablets, multiple fragments could be visible. Don't show Home Screen when File View is visible
            if (findViewById(R.id.main_activity_other_fragment).getVisibility() != View.VISIBLE) {
                findViewById(R.id.fragment_container_main_activity).setVisibility(View.VISIBLE);
            }
            showWalletBalance();
            findViewById(R.id.fragment_container_search).setVisibility(View.GONE);
        }
    });
    Context ctx = this;
    findViewById(R.id.clear_all_library_button).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(ctx).setTitle(R.string.confirm_clear_view_history_title).setMessage(R.string.confirm_clear_view_history).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    Thread t = new Thread(new Runnable() {

                        @Override
                        public void run() {
                            SQLiteDatabase db = DatabaseHelper.getInstance().getWritableDatabase();
                            DatabaseHelper.clearViewHistory(db);
                            runOnUiThread(new Runnable() {

                                @Override
                                public void run() {
                                    ((LibraryFragment) libraryFragment).onViewHistoryCleared();
                                }
                            });
                        }
                    });
                    t.start();
                }
            }).setNegativeButton(R.string.no, null);
            builder.show();
        }
    });
    findViewById(R.id.profile_button).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            findViewById(R.id.profile_button).setEnabled(false);
            LayoutInflater layoutInflater = (LayoutInflater) MainActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View customView = layoutInflater.inflate(R.layout.popup_user, null);
            PopupWindow popupWindow = new PopupWindow(customView, getScaledValue(240), WindowManager.LayoutParams.WRAP_CONTENT);
            popupWindow.setFocusable(true);
            popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {

                @Override
                public void onDismiss() {
                    findViewById(R.id.profile_button).setEnabled(true);
                }
            });
            ImageButton closeButton = customView.findViewById(R.id.popup_user_close_button);
            closeButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    popupWindow.dismiss();
                }
            });
            MaterialButton signUserButton = customView.findViewById(R.id.button_sign_user);
            View buttonChannels = customView.findViewById(R.id.button_channels);
            View buttonShowRewards = customView.findViewById(R.id.button_show_rewards);
            View buttonYouTubeSync = customView.findViewById(R.id.button_youtube_sync);
            View buttonSignOut = customView.findViewById(R.id.button_sign_out);
            TextView userIdText = customView.findViewById(R.id.user_id);
            AccountManager am = AccountManager.get(getApplicationContext());
            Account odyseeAccount = Helper.getOdyseeAccount(am.getAccounts());
            final boolean isSignedIn = odyseeAccount != null;
            buttonChannels.setVisibility(isSignedIn ? View.VISIBLE : View.GONE);
            buttonShowRewards.setVisibility(isSignedIn ? View.VISIBLE : View.GONE);
            buttonYouTubeSync.setVisibility(isSignedIn ? View.VISIBLE : View.GONE);
            buttonSignOut.setVisibility(isSignedIn ? View.VISIBLE : View.GONE);
            if (isSignedIn) {
                userIdText.setVisibility(View.VISIBLE);
                signUserButton.setVisibility(View.GONE);
                userIdText.setText(am.getUserData(odyseeAccount, "email"));
            } else {
                userIdText.setVisibility(View.GONE);
                userIdText.setText("");
                signUserButton.setVisibility(View.VISIBLE);
                signUserButton.setText(getString(R.string.sign_up_log_in));
            }
            customView.findViewById(R.id.button_app_settings).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    popupWindow.dismiss();
                    hideNotifications();
                    openFragment(SettingsFragment.class, true, null);
                }
            });
            customView.findViewById(R.id.button_community_guidelines).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    popupWindow.dismiss();
                    hideNotifications();
                    CustomTabColorSchemeParams.Builder ctcspb = new CustomTabColorSchemeParams.Builder();
                    ctcspb.setToolbarColor(ContextCompat.getColor(MainActivity.this, R.color.colorPrimary));
                    CustomTabColorSchemeParams ctcsp = ctcspb.build();
                    CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder().setDefaultColorSchemeParams(ctcsp);
                    CustomTabsIntent intent = builder.build();
                    intent.launchUrl(MainActivity.this, Uri.parse("https://odysee.com/@OdyseeHelp:b/Community-Guidelines:c"));
                }
            });
            customView.findViewById(R.id.button_help_support).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    popupWindow.dismiss();
                    hideNotifications();
                    CustomTabColorSchemeParams.Builder ctcspb = new CustomTabColorSchemeParams.Builder();
                    ctcspb.setToolbarColor(ContextCompat.getColor(MainActivity.this, R.color.colorPrimary));
                    CustomTabColorSchemeParams ctcsp = ctcspb.build();
                    CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder().setDefaultColorSchemeParams(ctcsp);
                    CustomTabsIntent intent = builder.build();
                    intent.launchUrl(MainActivity.this, Uri.parse("https://odysee.com/@OdyseeHelp:b?view=about"));
                }
            });
            buttonChannels.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    popupWindow.dismiss();
                    hideNotifications();
                    openFragment(ChannelManagerFragment.class, true, null);
                }
            });
            buttonShowRewards.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    popupWindow.dismiss();
                    hideNotifications();
                    openFragment(RewardsFragment.class, true, null);
                }
            });
            buttonYouTubeSync.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    popupWindow.dismiss();
                    hideNotifications();
                    startActivity(new Intent(MainActivity.this, YouTubeSyncActivity.class));
                }
            });
            signUserButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    // Close the popup window so its status gets updated when user opens it again
                    popupWindow.dismiss();
                    hideNotifications();
                    simpleSignIn(R.id.action_home_menu);
                }
            });
            buttonSignOut.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    popupWindow.dismiss();
                    hideNotifications();
                    if (isSignedIn) {
                        signOutUser();
                    }
                }
            });
            int[] coords = new int[2];
            View profileButton = findViewById(R.id.profile_button);
            profileButton.getLocationInWindow(coords);
            int ypos = coords[1] + profileButton.getHeight() - 32;
            popupWindow.showAtLocation(findViewById(R.id.fragment_container_main_activity), Gravity.TOP | Gravity.END, 24, ypos);
            View container = (View) popupWindow.getContentView().getParent();
            WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
            WindowManager.LayoutParams p = (WindowManager.LayoutParams) container.getLayoutParams();
            p.flags |= WindowManager.LayoutParams.FLAG_DIM_BEHIND;
            p.dimAmount = 0.3f;
            wm.updateViewLayout(container, p);
        }
    });
    findViewById(R.id.global_now_playing_close).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            stopExoplayer();
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
            nowPlayingClaim = null;
            nowPlayingClaimUrl = null;
            nowPlayingClaimBitmap = null;
            findViewById(R.id.miniplayer).setVisibility(View.GONE);
        }
    });
    findViewById(R.id.wunderbar_notifications).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            View container = findViewById(R.id.notifications_container);
            if (container.getVisibility() != View.VISIBLE) {
                showNotifications();
            } else {
                hideNotifications();
            }
        }
    });
    notificationsSwipeContainer = findViewById(R.id.notifications_list_swipe_container);
    notificationsSwipeContainer.setColorSchemeResources(R.color.odyseePink);
    notificationsSwipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            notificationsSwipeContainer.setRefreshing(true);
            loadRemoteNotifications(false);
        }
    });
    findViewById(R.id.global_now_playing_card).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (nowPlayingClaim != null && !Helper.isNullOrEmpty(nowPlayingClaimUrl)) {
                hideNotifications();
                openFileUrl(nowPlayingClaimUrl);
            }
        }
    });
    accountManager = AccountManager.get(this);
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) Account(android.accounts.Account) CustomTabColorSchemeParams(androidx.browser.customtabs.CustomTabColorSchemeParams) SpannableString(android.text.SpannableString) FileViewFragment(com.odysee.app.ui.findcontent.FileViewFragment) DialogFragment(androidx.fragment.app.DialogFragment) SettingsFragment(com.odysee.app.ui.other.SettingsFragment) FollowingFragment(com.odysee.app.ui.findcontent.FollowingFragment) LibraryFragment(com.odysee.app.ui.library.LibraryFragment) ContentScopeDialogFragment(com.odysee.app.dialog.ContentScopeDialogFragment) SearchFragment(com.odysee.app.ui.findcontent.SearchFragment) Fragment(androidx.fragment.app.Fragment) PublishFragment(com.odysee.app.ui.publish.PublishFragment) InvitesFragment(com.odysee.app.ui.wallet.InvitesFragment) PlaylistFragment(com.odysee.app.ui.library.PlaylistFragment) RewardsFragment(com.odysee.app.ui.wallet.RewardsFragment) WalletFragment(com.odysee.app.ui.wallet.WalletFragment) BaseFragment(com.odysee.app.ui.BaseFragment) AddToListsDialogFragment(com.odysee.app.dialog.AddToListsDialogFragment) AllContentFragment(com.odysee.app.ui.findcontent.AllContentFragment) PublishesFragment(com.odysee.app.ui.publish.PublishesFragment) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) LibraryFragment(com.odysee.app.ui.library.LibraryFragment) TextView(android.widget.TextView) Toolbar(androidx.appcompat.widget.Toolbar) EditText(android.widget.EditText) TextInputEditText(com.google.android.material.textfield.TextInputEditText) NavigationBarView(com.google.android.material.navigation.NavigationBarView) PlayerNotificationManager(com.google.android.exoplayer2.ui.PlayerNotificationManager) NotificationManager(android.app.NotificationManager) NotificationChannel(android.app.NotificationChannel) FragmentManager(androidx.fragment.app.FragmentManager) OnApplyWindowInsetsListener(androidx.core.view.OnApplyWindowInsetsListener) LayoutInflater(android.view.LayoutInflater) AccountManager(android.accounts.AccountManager) ActivityResultCallback(androidx.activity.result.ActivityResultCallback) AllContentFragment(com.odysee.app.ui.findcontent.AllContentFragment) DialogInterface(android.content.DialogInterface) PopupWindow(android.widget.PopupWindow) SearchFragment(com.odysee.app.ui.findcontent.SearchFragment) InputMethodManager(android.view.inputmethod.InputMethodManager) MaterialButton(com.google.android.material.button.MaterialButton) FirebaseMessagingToken(com.odysee.app.utils.FirebaseMessagingToken) WindowManager(android.view.WindowManager) KeyEvent(android.view.KeyEvent) ImageButton(android.widget.ImageButton) OnBackPressedCallback(androidx.activity.OnBackPressedCallback) BottomNavigationView(com.google.android.material.bottomnavigation.BottomNavigationView) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) PurchasedChecker(com.odysee.app.utils.PurchasedChecker) WebView(android.webkit.WebView) ViewTreeObserver(android.view.ViewTreeObserver) Context(android.content.Context) WalletFragment(com.odysee.app.ui.wallet.WalletFragment) SharedPreferences(android.content.SharedPreferences) MenuItem(android.view.MenuItem) CustomTabsIntent(androidx.browser.customtabs.CustomTabsIntent) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) ActivityResult(androidx.activity.result.ActivityResult) PlayerView(com.google.android.exoplayer2.ui.PlayerView) RecyclerView(androidx.recyclerview.widget.RecyclerView) ListView(android.widget.ListView) NavigationBarView(com.google.android.material.navigation.NavigationBarView) ImageView(android.widget.ImageView) View(android.view.View) WebView(android.webkit.WebView) BottomNavigationView(com.google.android.material.bottomnavigation.BottomNavigationView) TextView(android.widget.TextView) JSONException(org.json.JSONException) LbryUriException(com.odysee.app.exceptions.LbryUriException) ExecutionException(java.util.concurrent.ExecutionException) SQLiteException(android.database.sqlite.SQLiteException) LbryioRequestException(com.odysee.app.exceptions.LbryioRequestException) LbryioResponseException(com.odysee.app.exceptions.LbryioResponseException) ApiCallException(com.odysee.app.exceptions.ApiCallException) AuthTokenInvalidatedException(com.odysee.app.exceptions.AuthTokenInvalidatedException) ParseException(java.text.ParseException) SuppressLint(android.annotation.SuppressLint) WindowInsetsCompat(androidx.core.view.WindowInsetsCompat) CustomTabsIntent(androidx.browser.customtabs.CustomTabsIntent) DatabaseHelper(com.odysee.app.data.DatabaseHelper) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) FollowingFragment(com.odysee.app.ui.findcontent.FollowingFragment)

Example 2 with AllContentFragment

use of com.odysee.app.ui.findcontent.AllContentFragment in project odysee-android by OdyseeTeam.

the class MainActivity method loadSharedUserState.

private void loadSharedUserState() {
    // load wallet preferences
    LoadSharedUserStateTask loadTask = new LoadSharedUserStateTask(MainActivity.this, new LoadSharedUserStateTask.LoadSharedUserStateHandler() {

        @Override
        public void onSuccess(List<Subscription> subscriptions, List<Tag> followedTags, List<LbryUri> blockedChannels) {
            if (subscriptions != null && subscriptions.size() > 0) {
                // reload subscriptions if wallet fragment is FollowingFragment
                // openNavFragments.get
                MergeSubscriptionsTask mergeTask = new MergeSubscriptionsTask(subscriptions, initialSubscriptionMergeDone(), MainActivity.this, new MergeSubscriptionsTask.MergeSubscriptionsHandler() {

                    @Override
                    public void onSuccess(List<Subscription> subscriptions, List<Subscription> diff) {
                        Lbryio.subscriptions = new ArrayList<>(subscriptions);
                        if (!diff.isEmpty()) {
                            saveSharedUserState();
                        }
                        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
                        sp.edit().putBoolean(PREFERENCE_KEY_INTERNAL_INITIAL_SUBSCRIPTION_MERGE_DONE, true).apply();
                        Lbryio.cacheResolvedSubscriptions.clear();
                        FollowingFragment f = (FollowingFragment) getSupportFragmentManager().findFragmentByTag("FOLLOWING");
                        if (f != null) {
                            f.fetchLoadedSubscriptions(true);
                        }
                    }

                    @Override
                    public void onError(Exception error) {
                        Log.e(TAG, String.format("merge subscriptions failed: %s", error.getMessage()), error);
                    }
                });
                mergeTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            }
            if (followedTags != null && followedTags.size() > 0) {
                List<Tag> previousTags = new ArrayList<>(Lbry.followedTags);
                Lbry.followedTags = new ArrayList<>(followedTags);
                AllContentFragment f = (AllContentFragment) getSupportFragmentManager().findFragmentByTag("HOME");
                if (f != null) {
                    if (!f.isSingleTagView() && f.getCurrentContentScope() == ContentScopeDialogFragment.ITEM_TAGS && !previousTags.equals(followedTags)) {
                        f.fetchClaimSearchContent(true);
                    }
                }
            }
            if (blockedChannels != null && !blockedChannels.isEmpty()) {
                if (!initialBlockedListLoaded()) {
                    // first time the blocked list is loaded, so we attempt to merge the entries
                    List<LbryUri> newBlockedChannels = new ArrayList<>(Lbryio.blockedChannels);
                    for (LbryUri uri : blockedChannels) {
                        if (!newBlockedChannels.contains(uri)) {
                            newBlockedChannels.add(uri);
                        }
                    }
                    Lbryio.blockedChannels = new ArrayList<>(newBlockedChannels);
                    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
                    sp.edit().putBoolean(PREFERENCE_KEY_INTERNAL_INITIAL_BLOCKED_LIST_LOADED, true).apply();
                } else {
                    // replace the blocked channels list entirely
                    Lbryio.blockedChannels = new ArrayList<>(blockedChannels);
                }
            }
            if (!initialCollectionsLoaded()) {
                SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
                sp.edit().putBoolean(PREFERENCE_KEY_INTERNAL_INITIAL_COLLECTIONS_LOADED, true).apply();
            }
        }

        @Override
        public void onError(Exception error) {
            Log.e(TAG, String.format("load shared user state failed: %s", error != null ? error.getMessage() : "no error message"), error);
        }
    }, Lbryio.AUTH_TOKEN);
    loadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : AllContentFragment(com.odysee.app.ui.findcontent.AllContentFragment) LoadSharedUserStateTask(com.odysee.app.tasks.wallet.LoadSharedUserStateTask) SharedPreferences(android.content.SharedPreferences) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) LbryUriException(com.odysee.app.exceptions.LbryUriException) ExecutionException(java.util.concurrent.ExecutionException) SQLiteException(android.database.sqlite.SQLiteException) LbryioRequestException(com.odysee.app.exceptions.LbryioRequestException) LbryioResponseException(com.odysee.app.exceptions.LbryioResponseException) ApiCallException(com.odysee.app.exceptions.ApiCallException) AuthTokenInvalidatedException(com.odysee.app.exceptions.AuthTokenInvalidatedException) ParseException(java.text.ParseException) MergeSubscriptionsTask(com.odysee.app.tasks.MergeSubscriptionsTask) FollowingFragment(com.odysee.app.ui.findcontent.FollowingFragment) ArrayList(java.util.ArrayList) List(java.util.List) Tag(com.odysee.app.model.Tag) Subscription(com.odysee.app.model.lbryinc.Subscription) LbryUri(com.odysee.app.utils.LbryUri)

Example 3 with AllContentFragment

use of com.odysee.app.ui.findcontent.AllContentFragment in project odysee-android by OdyseeTeam.

the class MainActivity method displayDynamicCategories.

private void displayDynamicCategories() {
    Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_container_main_activity);
    if (fragment instanceof AllContentFragment) {
        ((AllContentFragment) fragment).displayDynamicCategories();
    }
    hideLaunchScreen();
}
Also used : AllContentFragment(com.odysee.app.ui.findcontent.AllContentFragment) FileViewFragment(com.odysee.app.ui.findcontent.FileViewFragment) DialogFragment(androidx.fragment.app.DialogFragment) SettingsFragment(com.odysee.app.ui.other.SettingsFragment) FollowingFragment(com.odysee.app.ui.findcontent.FollowingFragment) LibraryFragment(com.odysee.app.ui.library.LibraryFragment) ContentScopeDialogFragment(com.odysee.app.dialog.ContentScopeDialogFragment) SearchFragment(com.odysee.app.ui.findcontent.SearchFragment) Fragment(androidx.fragment.app.Fragment) PublishFragment(com.odysee.app.ui.publish.PublishFragment) InvitesFragment(com.odysee.app.ui.wallet.InvitesFragment) PlaylistFragment(com.odysee.app.ui.library.PlaylistFragment) RewardsFragment(com.odysee.app.ui.wallet.RewardsFragment) WalletFragment(com.odysee.app.ui.wallet.WalletFragment) BaseFragment(com.odysee.app.ui.BaseFragment) AddToListsDialogFragment(com.odysee.app.dialog.AddToListsDialogFragment) AllContentFragment(com.odysee.app.ui.findcontent.AllContentFragment) PublishesFragment(com.odysee.app.ui.publish.PublishesFragment)

Aggregations

SharedPreferences (android.content.SharedPreferences)2 SQLiteException (android.database.sqlite.SQLiteException)2 DialogFragment (androidx.fragment.app.DialogFragment)2 Fragment (androidx.fragment.app.Fragment)2 AllContentFragment (com.odysee.app.ui.findcontent.AllContentFragment)2 FollowingFragment (com.odysee.app.ui.findcontent.FollowingFragment)2 Account (android.accounts.Account)1 AccountManager (android.accounts.AccountManager)1 SuppressLint (android.annotation.SuppressLint)1 NotificationChannel (android.app.NotificationChannel)1 NotificationManager (android.app.NotificationManager)1 PendingIntent (android.app.PendingIntent)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 Editable (android.text.Editable)1 SpannableString (android.text.SpannableString)1 TextWatcher (android.text.TextWatcher)1 KeyEvent (android.view.KeyEvent)1