Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Android Main Activity
public class DrawerActivity extends BaseActivity
implements NavigationView.OnNavigationItemSelectedListener,HomeFragment.OnItemClickListenerInFragment {
public FragmentManager fm;
@BindView(R.id.drawer_layout)
DrawerLayout drawer;
@BindView(R.id.toolbar)
Toolbar toolbar;
@BindView(R.id.nav_view)
NavigationView navigationView;
Boolean isLoggedIn = false;
@BindView(R.id.fab)
FloatingActionButton fab;
HashMap<Integer,String> map;
Resources resources;
private InterstitialAd mInterstitialAd;
int currentposition;
AdRequest adRequest;
Attractions.GetData currentItem;
private int price_id;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_drawer);
ButterKnife.bind(this);
resources=getResources();
map=new HashMap<Integer,String>();
boolean isAlreadyUpdated=SharedPreference.getInstance().getBoolean(this,SharedPreference.FCM_TOKEN_UPDATED);
if(!isAlreadyUpdated)
updateToken(SharedPreference.getInstance().getString(this,SharedPreference.FCM_TOKEN));
setSupportActionBar(toolbar);
toolbar.setSubtitle("संजीव मोगा बिशनोई");
fm = getSupportFragmentManager();
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
navigationView.setNavigationItemSelectedListener(this);
if (findViewById(R.id.fragment_container) != null) {
currentFragment(105, null);
}
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//CommonUtils.ShareApp(DrawerActivity.this);
Intent i = new Intent(DrawerActivity.this, stayrocks.jambh.vani.music.MainActivity.class);
i.putExtra("slug","audioshabad");
startActivity(i);
}
});
getCategories();
try{
if(!SharedPreference.getInstance().getBoolean(this,SharedPreference.ALARAMSET,false)) {
NotificationHelper.scheduleRepeatingElapsedNotification(this);
SharedPreference.getInstance().saveBoolean(this,SharedPreference.ALARAMSET,true);
NotificationHelper.enableBootReceiver(this);
}
}catch (Exception e){
}
// Intent intentR=getIntent();
// if(intentR!=null){
// if(intentR.getBooleanExtra("isMessage",false)){
// startActivity(new Intent(DrawerActivity.this, stayrocks.jambh.vani.groupchat.MainActivity.class));
// }else{
// // Log.e("new intnet",intentR.getExtras()!=null?intentR.getExtras().toString():intentR.toString());
// //Toast.makeText(this,"new intnent",Toast.LENGTH_LONG).show();
// if(intentR.getExtras()!=null && (intentR.getStringExtra("post_id")!=null)) {
// Intent i = new Intent(this, DealsListActivity.class);
// i.putExtra("storetitle", intentR.getStringExtra("post_title"));
// i.putExtra("storeid", intentR.getStringExtra("post_id") + "");
// //i.putExtra("data", null);
// startActivity(i);
// }
// }
// }
//addMenuItemInNavMenuDrawer();
}
@Override
protected void onStart() {
super.onStart();
adRequest=new AdRequest.Builder().build();
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId(getResources().getString(R.string.splash));
mInterstitialAd.loadAd(new AdRequest.Builder().build());
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
super.onAdClosed();
//mInterstitialAd.loadAd(adRequest);
startNewActivity(currentposition);
}
});
}
public void showAd(int currentposition,Attractions.GetData currentItem){
this.currentItem=currentItem;
this.currentposition=currentposition;
if(currentposition%2==1 && mInterstitialAd.isLoaded() && !MyApplication.getInstance().getProStatus()){
mInterstitialAd.show();
}else{
startNewActivity(currentposition);
}
}
@Override
public void onBackPressed() {
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
if (fm.getBackStackEntryCount() == 1) {
finish();
} else {
/* if (getCurrentFragment() instanceof MusicFragment) {
MusicFragment mf = (MusicFragment) getCurrentFragment();
if(mf.isShown()){
mf.reset(false);
return;
}
}*/
super.onBackPressed();
// HighLightTab();
}
/*}*/
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.drawer, menu);
// login_logout = menu.findItem(R.id.action_login);
// update_sesssion_data();
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.about) {
//CommonUtils.ShareApp(DrawerActivity.this);
startActivity(new Intent(DrawerActivity.this, stayrocks.jambh.vani.settings.SettingsActivity.class));
return true;
}
return super.onOptionsItemSelected(item);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
int group_id=item.getGroupId();
int id = item.getItemId();
// Toast.makeText(getApplicationContext(),group_id+" "+id,Toast.LENGTH_LONG).show();
if(group_id==R.id.groupcategory){
if(map.size()>0){
String slug=map.get(id);
// Toast.makeText(getApplicationContext(),title,Toast.LENGTH_LONG).show();
Bundle bundle = new Bundle();
bundle.putString("slug",slug);
currentFragment(106,bundle);
}
}else {
// Handle navigation view item clicks here.
if (id == R.id.nav_home) {
currentFragment(105, null);
}
// if (id == R.id.nav_nearby) {
//
// startActivity(new Intent(this, VideoListDemoActivity.class).setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION));
// return true;
//
// }
//
// if (id == R.id.nav_my_jyot) {
//
// startActivity(new Intent(this, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION));
// return true;
//
// }
if(id == R.id.nav_rating){
new EasyRatingDialog(this).rateNow();
}
if(id == R.id.nav_spread_love){
CommonUtils.ShareApp(this);
}
if(id == R.id.nav_contactus){
String mailto = "mailto:<Your Email Id>";
Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
emailIntent.setData(Uri.parse(mailto));
try {
startActivity(emailIntent);
} catch (ActivityNotFoundException e) {
//TODO: Handle case where no email app is available
}
}
}
drawer.closeDrawer(GravityCompat.START);
return true;
}
public void currentFragment(int position, Bundle bundle) {
switch (position) {
case 106:
addFragment(HomeFragment.newInstance(bundle.getString("slug"),"",0),bundle.getString("slug"));
break;
default:
//replaceFragment(new Shabad(), "Main");
//replaceFragment(MainFragment.newInstance("",""), "Main");
replaceFragment(HomeFragment.newInstance("recent","recent",0),"recent");
break;
}
}
private void replaceFragment(Fragment fragment, String tag) {
String backStateName = fragment.getClass().getName();
try {
boolean fragmentPopped = fm.popBackStackImmediate(backStateName, 0);
if (!fragmentPopped && fm.findFragmentByTag(backStateName) == null) {
//fragment not in back stack, create it.
FragmentTransaction ft = fm.beginTransaction();
ft.add(R.id.fragment_container, fragment, backStateName);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
ft.addToBackStack(backStateName);
ft.commitAllowingStateLoss();
//ft.commit();
}
} catch (Exception e) {
e.printStackTrace();
}
}
private void addFragment(Fragment fragment, String tag) {
String backStateName = tag;
try {
boolean fragmentPopped = fm.popBackStackImmediate(backStateName, 0);
if (!fragmentPopped && fm.findFragmentByTag(backStateName) == null) {
//fragment not in back stack, create it.
FragmentTransaction ft = fm.beginTransaction();
ft.add(R.id.fragment_container, fragment, backStateName);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
ft.addToBackStack(backStateName);
ft.commitAllowingStateLoss();
//ft.commit();
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
protected void onResume() {
super.onResume();
}
public void updateToken(String token){
ApiInterface apiService =
ApiClient.getClient(getApplicationContext()).create(ApiInterface.class);
Call<General> call = apiService.updateDeviceToken(token);
call.enqueue(new Callback<General>() {
@Override
public void onResponse(Call<General> call, Response<General> response) {
General feed = response.body();
if (feed != null) {
SharedPreference.getInstance().saveBoolean(getApplicationContext(), SharedPreference.FCM_TOKEN_UPDATED,true);
}
}
@Override
public void onFailure(Call<General> call, Throwable t) {
SharedPreference.getInstance().saveBoolean(getApplicationContext(), SharedPreference.FCM_TOKEN_UPDATED,false);
}
});
}
public void getCategories() {
ApiInterface apiService =
ApiClient.getClient(this).create(ApiInterface.class);
Call<AllCategories> call = apiService.getAllCategories();
call.enqueue(new Callback<AllCategories>() {
@Override
public void onResponse(Call<AllCategories> call, Response<AllCategories> response) {
AllCategories feed = response.body();
// CommonUtils.hideCustomProgress(loaderlayout);
if (feed != null) {
if (feed.status.equalsIgnoreCase("OK")) {
try {
NavigationView navView = (NavigationView) findViewById(R.id.nav_view);
Menu menu = navView.getMenu();
Menu submenu = menu.addSubMenu(R.id.groupcategory,Menu.NONE,2,"Categories");
map.clear();
submenu.clear();
navView.invalidate();
for (AllCategories.GetData data:
feed.GetData) {
map.put(data.cat_ID,data.slug);
MenuItem item=submenu.add(R.id.groupcategory,data.cat_ID,data.cat_ID,data.cat_name);
item.setIcon(R.mipmap.ic_launcher);
item.setCheckable(true);
}
navView.invalidate();
}catch (Exception e){
}
} else {
}
}else {
}
}
@Override
public void onFailure(Call<AllCategories> call, Throwable t) {
// CommonUtils.hideProgress(getActivity());
//onLoginFailed();
t.printStackTrace();
}
});
}
@Override
public void openDrawer() {
if(drawer!=null){
drawer.openDrawer(GravityCompat.START);
}
}
void startNewActivity(int position){
Intent i=null;
if(currentItem!=null && currentItem.post_type.equalsIgnoreCase("youtube")){
i = new Intent(this, PlayerActivity.class);
i.putExtra("videoid", currentItem.link);
startActivity(i);
}else if(currentItem!=null && currentItem.post_type.equalsIgnoreCase("ad")){
// do nothing in case of add
}else if(currentItem!=null && currentItem.post_type.equalsIgnoreCase("audio")) {
Intent audio_i= new Intent(this, AudioPlayerActivity.class);
audio_i.putExtra("link",currentItem.link);
audio_i.putExtra("srt_link",currentItem.srt_link);
startActivity(audio_i);
}else if(currentItem!=null && currentItem.post_type.equalsIgnoreCase("doc")) {
Uri uriUrl = Uri.parse(currentItem.link);
Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
startActivity(launchBrowser);
}else if(currentItem!=null && currentItem.post_type.equalsIgnoreCase("promotion")) {
Uri uriUrl = Uri.parse(currentItem.link);
Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
startActivity(launchBrowser);
}
else{
i=new Intent(this, DealsListActivity.class);
i.putExtra("storetitle",currentItem.title);
i.putExtra("storeid",currentItem.post_id+"");
i.putExtra("data",currentItem);
startActivity(i);
}
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.