package what.whatandroid.notifications;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.FragmentManager;
import android.view.Window;
import api.soup.MySoup;
import what.whatandroid.R;
import what.whatandroid.announcements.AnnouncementsActivity;
import what.whatandroid.barcode.BarcodeActivity;
import what.whatandroid.bookmarks.BookmarksActivity;
import what.whatandroid.callbacks.ViewTorrentCallbacks;
import what.whatandroid.forums.ForumActivity;
import what.whatandroid.inbox.InboxActivity;
import what.whatandroid.login.LoggedInActivity;
import what.whatandroid.profile.ProfileActivity;
import what.whatandroid.search.SearchActivity;
import what.whatandroid.subscriptions.SubscriptionsActivity;
import what.whatandroid.top10.Top10Activity;
import what.whatandroid.torrentgroup.TorrentGroupActivity;
/**
* Activity for viewing torrent notifications
*/
public class NotificationsActivity extends LoggedInActivity implements ViewTorrentCallbacks {
private NotificationsFragment fragment;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_frame);
setupNavDrawer();
setTitle(getTitle());
FragmentManager fm = getSupportFragmentManager();
if (savedInstanceState != null){
fragment = (NotificationsFragment)fm.findFragmentById(R.id.container);
}
else {
fragment = new NotificationsFragment();
fm.beginTransaction().add(R.id.container, fragment).commit();
}
//Since we're viewing the notifications unset the new notifications flag
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
preferences.edit()
.putInt(getString(R.string.key_pref_num_notifications), 0)
.apply();
}
@Override
public void onLoggedIn(){
fragment.onLoggedIn();
}
@Override
public void viewTorrentGroup(int id){
Intent intent = new Intent(this, TorrentGroupActivity.class);
intent.putExtra(TorrentGroupActivity.GROUP_ID, id);
startActivity(intent);
}
@Override
public void viewTorrent(int group, int torrent){
Intent intent = new Intent(this, TorrentGroupActivity.class);
intent.putExtra(TorrentGroupActivity.GROUP_ID, group);
intent.putExtra(TorrentGroupActivity.TORRENT_ID, torrent);
startActivity(intent);
}
@Override
public void onNavigationDrawerItemSelected(int position){
if (navDrawer == null){
return;
}
String selection = navDrawer.getItem(position);
if (selection.equalsIgnoreCase(getString(R.string.announcements))){
Intent intent = new Intent(this, AnnouncementsActivity.class);
intent.putExtra(AnnouncementsActivity.SHOW, AnnouncementsActivity.ANNOUNCEMENTS);
startActivity(intent);
}
else if (selection.equalsIgnoreCase(getString(R.string.profile))){
Intent intent = new Intent(this, ProfileActivity.class);
intent.putExtra(ProfileActivity.USER_ID, MySoup.getUserId());
startActivity(intent);
}
else if (selection.equalsIgnoreCase(getString(R.string.bookmarks))){
Intent intent = new Intent(this, BookmarksActivity.class);
startActivity(intent);
}
else if (selection.equalsIgnoreCase(getString(R.string.blog))){
Intent intent = new Intent(this, AnnouncementsActivity.class);
intent.putExtra(AnnouncementsActivity.SHOW, AnnouncementsActivity.BLOGS);
startActivity(intent);
}
else if (selection.contains(getString(R.string.messages))){
Intent intent = new Intent(this, InboxActivity.class);
startActivity(intent);
}
else if (selection.contains(getString(R.string.subscriptions))){
Intent intent = new Intent(this, SubscriptionsActivity.class);
startActivity(intent);
}
else if (selection.equalsIgnoreCase(getString(R.string.forums))){
Intent intent = new Intent(this, ForumActivity.class);
startActivity(intent);
}
else if (selection.equalsIgnoreCase(getString(R.string.top10))){
Intent intent = new Intent(this, Top10Activity.class);
startActivity(intent);
}
else if (selection.equalsIgnoreCase(getString(R.string.torrents))){
Intent intent = new Intent(this, SearchActivity.class);
intent.putExtra(SearchActivity.SEARCH, SearchActivity.TORRENT);
startActivity(intent);
}
else if (selection.equalsIgnoreCase(getString(R.string.artists))){
Intent intent = new Intent(this, SearchActivity.class);
intent.putExtra(SearchActivity.SEARCH, SearchActivity.ARTIST);
startActivity(intent);
}
else if (selection.equalsIgnoreCase(getString(R.string.requests))){
Intent intent = new Intent(this, SearchActivity.class);
intent.putExtra(SearchActivity.SEARCH, SearchActivity.REQUEST);
startActivity(intent);
}
else if (selection.equalsIgnoreCase(getString(R.string.users))){
Intent intent = new Intent(this, SearchActivity.class);
intent.putExtra(SearchActivity.SEARCH, SearchActivity.USER);
startActivity(intent);
}
else if (selection.equalsIgnoreCase(getString(R.string.barcode_lookup))){
Intent intent = new Intent(this, BarcodeActivity.class);
startActivity(intent);
}
}
}