use of com.odysee.app.ui.findcontent.SearchFragment 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);
}
use of com.odysee.app.ui.findcontent.SearchFragment in project odysee-android by OdyseeTeam.
the class MainActivity method launchSearch.
/*
private void setupUriBar() {
findViewById(R.id.wunderbar_close).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
clearWunderbarFocus(view);
}
});
EditText wunderbar = findViewById(R.id.wunderbar);
wunderbar.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
if (hasFocus) {
hideNotifications();
findViewById(R.id.wunderbar_notifications).setVisibility(View.INVISIBLE);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(view, 0);
} else {
findViewById(R.id.wunderbar_notifications).setVisibility(View.VISIBLE);
}
if (canShowUrlSuggestions()) {
toggleUrlSuggestions(hasFocus);
if (hasFocus && Helper.isNullOrEmpty(Helper.getValue(((EditText) view).getText()))) {
displayUrlSuggestionsForNoInput();
}
}
}
});
wunderbar.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
if (charSequence != null && canShowUrlSuggestions()) {
handleUriInputChanged(charSequence.toString().trim());
}
}
@Override
public void afterTextChanged(Editable editable) {
}
});
wunderbar.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
if (actionId == EditorInfo.IME_ACTION_GO) {
String input = Helper.getValue(wunderbar.getText());
boolean handled = false;
if (input.startsWith(LbryUri.PROTO_DEFAULT) && !input.equalsIgnoreCase(LbryUri.PROTO_DEFAULT)) {
try {
LbryUri uri = LbryUri.parse(input);
if (uri.isChannel()) {
openChannelUrl(uri.toString());
clearWunderbarFocus(wunderbar);
handled = true;
} else {
openFileUrl(uri.toString());
clearWunderbarFocus(wunderbar);
handled = true;
}
} catch (LbryUriException ex) {
// pass
}
}
if (!handled) {
// search
launchSearch(input);
clearWunderbarFocus(wunderbar);
}
return true;
}
return false;
}
});
urlSuggestionListAdapter = new UrlSuggestionListAdapter(this);
urlSuggestionListAdapter.setListener(new UrlSuggestionListAdapter.UrlSuggestionClickListener() {
@Override
public void onUrlSuggestionClicked(UrlSuggestion urlSuggestion) {
switch (urlSuggestion.getType()) {
case UrlSuggestion.TYPE_CHANNEL:
// open channel page
if (urlSuggestion.getClaim() != null) {
openChannelClaim(urlSuggestion.getClaim());
} else {
openChannelUrl(urlSuggestion.getUri().toString());
}
break;
case UrlSuggestion.TYPE_FILE:
if (urlSuggestion.getClaim() != null) {
openFileClaim(urlSuggestion.getClaim());
} else {
openFileUrl(urlSuggestion.getUri().toString());
}
break;
case UrlSuggestion.TYPE_SEARCH:
launchSearch(urlSuggestion.getText());
break;
case UrlSuggestion.TYPE_TAG:
// open tag page
openAllContentFragmentWithTag(urlSuggestion.getText());
break;
}
clearWunderbarFocus(findViewById(R.id.wunderbar));
}
});
RecyclerView urlSuggestionList = findViewById(R.id.url_suggestions);
LinearLayoutManager llm = new LinearLayoutManager(this);
urlSuggestionList.setLayoutManager(llm);
urlSuggestionList.setAdapter(urlSuggestionListAdapter);
}
public void clearWunderbarFocus(View view) {
findViewById(R.id.wunderbar).clearFocus();
findViewById(R.id.appbar).requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
public View getWunderbar() {
return findViewById(R.id.wunderbar);
}
*/
private void launchSearch(String text) {
Fragment currentFragment = getCurrentFragment();
if (currentFragment instanceof SearchFragment) {
((SearchFragment) currentFragment).search(text, 0);
} else {
try {
SearchFragment fragment = SearchFragment.class.newInstance();
fragment.setCurrentQuery(text);
openFragment(fragment, true);
} catch (Exception ex) {
// pass
}
}
}
use of com.odysee.app.ui.findcontent.SearchFragment in project odysee-android by OdyseeTeam.
the class MainActivity method renderFullMode.
private void renderFullMode() {
if (!inFullscreenMode) {
showActionBar();
} else {
View v = findViewById(R.id.appbar);
if (v != null) {
v.setFitsSystemWindows(false);
}
}
Fragment fragment = getCurrentFragment();
boolean inMainView = currentDisplayFragment == null;
boolean inFileView = fragment instanceof FileViewFragment;
boolean inChannelView = fragment instanceof ChannelFragment;
boolean inSearchView = fragment instanceof SearchFragment;
findViewById(R.id.main_activity_other_fragment).setVisibility(!inMainView ? View.VISIBLE : View.GONE);
findViewById(R.id.content_main).setVisibility(View.VISIBLE);
findViewById(R.id.fragment_container_main_activity).setVisibility(inMainView ? View.VISIBLE : View.GONE);
if (inMainView) {
showBottomNavigation();
}
findViewById(R.id.appbar).setVisibility(inMainView || inSearchView ? View.VISIBLE : View.GONE);
if (!inFileView && !inFullscreenMode && nowPlayingClaim != null) {
findViewById(R.id.miniplayer).setVisibility(View.VISIBLE);
setPlayerForMiniPlayerView();
}
View pipPlayerContainer = findViewById(R.id.pip_player_container);
PlayerView pipPlayer = findViewById(R.id.pip_player);
pipPlayer.setPlayer(null);
pipPlayerContainer.setVisibility(View.GONE);
playerReassigned = true;
}
Aggregations