use of com.odysee.app.data.DatabaseHelper 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.data.DatabaseHelper in project odysee-android by OdyseeTeam.
the class LbrynetMessagingService method onMessageReceived.
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
if (firebaseAnalytics == null) {
firebaseAnalytics = FirebaseAnalytics.getInstance(this);
}
Map<String, String> payload = remoteMessage.getData();
if (payload != null) {
String type = payload.get("type");
String url = payload.get("target");
String title = payload.get("title");
String body = payload.get("body");
// notification name
String name = payload.get("name");
// comment hash
String hash = payload.get("hash");
if (type != null && getEnabledTypes().contains(type) && body != null && body.trim().length() > 0) {
// only log the receive event for valid notifications received
if (firebaseAnalytics != null) {
Bundle bundle = new Bundle();
bundle.putString("name", name);
firebaseAnalytics.logEvent(LbryAnalytics.EVENT_LBRY_NOTIFICATION_RECEIVE, bundle);
}
if (!Helper.isNullOrEmpty(hash)) {
url = String.format("%s?comment_hash=%s", url, hash);
}
sendNotification(title, body, type, url, name);
}
// persist the notification data
try {
DatabaseHelper helper = DatabaseHelper.getInstance();
SQLiteDatabase db = helper.getWritableDatabase();
LbryNotification lnotification = new LbryNotification();
lnotification.setTitle(title);
lnotification.setDescription(body);
lnotification.setTargetUrl(url);
lnotification.setTimestamp(new Date());
DatabaseHelper.createOrUpdateNotification(lnotification, db);
// send a broadcast
Intent intent = new Intent(ACTION_NOTIFICATION_RECEIVED);
intent.putExtra("title", title);
intent.putExtra("body", body);
intent.putExtra("url", url);
intent.putExtra("timestamp", lnotification.getTimestamp().getTime());
sendBroadcast(intent);
} catch (Exception ex) {
// don't fail if any error occurs while saving a notification
Log.e(TAG, "could not save notification", ex);
}
}
}
use of com.odysee.app.data.DatabaseHelper in project odysee-android by OdyseeTeam.
the class GetLocalNotificationsSupplier method get.
@Override
public List<LbryNotification> get() {
List<LbryNotification> notifications = new ArrayList<>();
DatabaseHelper dbHelper = DatabaseHelper.getInstance();
try {
SQLiteDatabase db = dbHelper.getReadableDatabase();
notifications = DatabaseHelper.getNotifications(db);
} catch (Exception ex) {
ex.printStackTrace();
}
return notifications;
}
use of com.odysee.app.data.DatabaseHelper in project odysee-android by OdyseeTeam.
the class DeleteViewHistoryItem method run.
@Override
public void run() {
DatabaseHelper dbHelper = DatabaseHelper.getInstance();
SQLiteDatabase db = dbHelper.getWritableDatabase();
if (db != null) {
try {
DatabaseHelper.removeViewHistoryItem(db, url);
} catch (Exception e) {
e.printStackTrace();
}
dbHelper.close();
}
}
use of com.odysee.app.data.DatabaseHelper in project odysee-android by OdyseeTeam.
the class Helper method saveUrlHistory.
public static void saveUrlHistory(String url, String title, int type) {
DatabaseHelper dbHelper = DatabaseHelper.getInstance();
if (dbHelper != null) {
UrlSuggestion suggestion = new UrlSuggestion();
suggestion.setUri(LbryUri.tryParse(url));
suggestion.setType(type);
suggestion.setText(Helper.isNull(title) ? "" : title);
new SaveUrlHistoryTask(suggestion, dbHelper, null).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
Aggregations