1)HomeScreen.java
package com.credencys.goscoop.activities; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.database.Cursor; import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.GradientDrawable; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.support.design.widget.CoordinatorLayout; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.NavigationView; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentTransaction; import android.support.v4.content.ContextCompat; import android.support.v4.content.LocalBroadcastManager; import android.support.v4.view.GravityCompat; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; import android.util.Log; import android.view.Gravity; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.Window; import android.view.WindowManager; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; import com.afollestad.materialdialogs.DialogAction; import com.afollestad.materialdialogs.MaterialDialog; import com.bumptech.glide.Glide; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.signature.StringSignature; import com.credencys.goscoop.R; import com.credencys.goscoop.customfunctions.ScrollAwareFABBehavior; import com.credencys.goscoop.custommenu.CustomMenuItem; import com.credencys.goscoop.custommenu.MyAdapter; import com.credencys.goscoop.custommenu.RecyclerItemClickListener; import com.credencys.goscoop.database.DatabaseHandler; import com.credencys.goscoop.fragments.AboutUsFragment; import com.credencys.goscoop.fragments.CelebrationScreen; import com.credencys.goscoop.fragments.FeedFragment; import com.credencys.goscoop.fragments.FragmentDashboardProfile; import com.credencys.goscoop.fragments.InboxFragment; import com.credencys.goscoop.fragments.PollsAndSurveyList; import com.credencys.goscoop.fragments.SuggestionsFeedbackScreen; import com.credencys.goscoop.fragments.TopStoriesFrag; import com.credencys.goscoop.interfaces.AsyncTaskCompleteListener; import com.credencys.goscoop.utils.AppPrefs; import com.credencys.goscoop.utils.ConnectionDetector; import com.credencys.goscoop.utils.StaticUtils; import com.credencys.goscoop.webresponses.joinedrooms.JoinedRooms; import com.credencys.goscoop.webservices.RestClient; import com.credencys.goscoop.xmppgroupchat.ChatGroupListFragment; import com.credencys.goscoop.xmppgroupchat.ChatRoomActivity; import org.json.JSONException; import org.json.JSONObject; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import retrofit.Callback; import retrofit.RetrofitError; import retrofit.client.Response; public class HomeScreen extends AppCompatActivity implements AsyncTaskCompleteListener, View.OnClickListener { public static FloatingActionButton FAB_CREATE_ART; public static String CHANNEL_ID; public static String FRAGPOSITION; public static String CHANNEL_NAME; public static Context CONTEXT_HOME; public static boolean INTEREST_UPDATED; public static boolean FLAG_PROF_UPDATED; public static MyAdapter mAdapterMenu; public static String mClrMenuItems, mClrMenuItemSel, mClrInner; // private CircleProgressBar mProgView; private RelativeLayout mRelLayHomeScree; public static TextView mTvUname, txtProffession; private TextView mTvActionBarTitle, txtLogout, txtEditProfile; public static ImageView mIvProfPic; private ArrayList<CustomMenuItem> mArrMenuItems; public boolean isActivityPaused = false; private String mPosBtnClr, mNegBtnClr; // private CircleProgressBar imgProgView; boolean doubleBackToExitPressedOnce = false; private ImageView mBtnSearch; private TextView txtEdit; //private Intent mService; private String appLabel; private RelativeLayout rlytProfile; private boolean mConnectChat; TextView mTvPoweredBy, mTvGoscoop; Fragment mCorrentFragment; // private Dialog progressDialog; @Override protected void onCreate(Bundle savedInstanceState) { // Activate StrictMode /*StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() .detectAll() .detectDiskReads() .detectDiskWrites() .detectNetwork() // alternatively .detectAll() for all detectable problems .penaltyLog() .penaltyDeath() .build()); StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() .detectLeakedSqlLiteObjects() .detectLeakedClosableObjects() // alternatively.detectAll() for all detectable problems .penaltyLog() .penaltyDeath() .build());*/ super.onCreate(savedInstanceState); setContentView(R.layout.activity_home_screen); CONTEXT_HOME = HomeScreen.this; AppPrefs.getInstance(HomeScreen.this).setBdayPagerClose("1"); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { ImageView iv = (ImageView) findViewById(R.id.xLinLayShadow); // iv.setVisibility(View.VISIBLE); } /*ConnectChat connChat = new ConnectChat(getApplicationContext(), this); connChat.execute();*/ Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); StaticUtils.setupUI(toolbar, HomeScreen.this); mBtnSearch = (ImageView) toolbar.findViewById(R.id.xBtnSearch); mBtnSearch.setVisibility(View.VISIBLE); if (!ConnectionDetector.getInstance(this).isOnline()) { mBtnSearch.setImageResource(R.mipmap.search); } if (ConnectionDetector.getInstance(this).isOnline()) { mSendUpdatedDate(); appLabel = getString(R.string.app_name) + " for " + AppPrefs.getInstance(HomeScreen.this).getOrgName().toLowerCase(); mRelLayHomeScree = (RelativeLayout) findViewById(R.id.xLayHomeScreen); //FLAG_PROF_UPDATED = false; INTEREST_UPDATED = false; int width = getResources().getDisplayMetrics().widthPixels; getSupportActionBar().setHomeAsUpIndicator(ContextCompat.getDrawable(CONTEXT_HOME, R.mipmap.menu)); getSupportActionBar().setElevation(0); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window window = getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor(Color.parseColor(AppPrefs.getInstance(this).getOthrCode("os_topheader_bg_color"))); } FAB_CREATE_ART = (FloatingActionButton) findViewById(R.id.fab); mSetupFab(false); mTvActionBarTitle = (TextView) toolbar.findViewById(R.id.xTvHomeScreenTitle); // mTvActionBarTitle.setGravity(Gravity.CENTER); mTvActionBarTitle.setText(appLabel); txtEdit = (TextView) toolbar.findViewById(R.id.txtEdit); txtEdit.setVisibility(View.GONE); txtEdit.setClickable(true); txtEdit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { } }); mBtnSearch.setClickable(true); mBtnSearch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(HomeScreen.this, SearchableActivity.class); startActivity(i); } }); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.addDrawerListener(toggle); toggle.syncState(); View header = drawer.findViewById(R.id.xlayoutHeader); // DrawerLayout.LayoutParams params = (android.support.v4.widget.DrawerLayout.LayoutParams) header.getLayoutParams();// params.width = width - (width / 3);// header.setLayoutParams(params); final NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); // DrawerLayout.LayoutParams paramsNavView = (android.support.v4.widget.DrawerLayout.LayoutParams) navigationView.getLayoutParams();// paramsNavView.width = width - (width / 3);// navigationView.setLayoutParams(paramsNavView); View v = navigationView.findViewById(R.id.xlayoutFooter); LinearLayout lytContact = (LinearLayout) findViewById(R.id.lytContact); lytContact.setOnClickListener(this); ImageView imgPoweredBy = (ImageView) findViewById(R.id.imgPoweredBy); imgPoweredBy.setOnClickListener(this); mTvPoweredBy = (TextView) v.findViewById(R.id.xTvPoweredBy); mTvGoscoop = (TextView) v.findViewById(R.id.xTvGoscoop); txtLogout = (TextView) v.findViewById(R.id.txtLogout); txtLogout.setOnClickListener(this); // String s = getResources().getString(R.string.powered_by);// SpannableString ss1 = new SpannableString(s);// ss1.setSpan(new RelativeSizeSpan(1.5f), 11, 20, 0); // set size// mTvPoweredBy.setTextSize(9); v.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // mBtnSearch.setVisibility(View.INVISIBLE);// mBtnSearch.setClickable(false);// mTvActionBarTitle.setText(getString(R.string.about_astrum));// mTvActionBarTitle.setGravity(Gravity.CENTER);// mReplaceFragment(new AboutUsFragment(), null);// // update selected item and title, then close the drawer// DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);// drawer.closeDrawer(GravityCompat.START);// mAdapterMenu.setSelection(-1);// mAdapterMenu.notifyDataSetChanged(); } }); // DETECT CLICK ON PROFILE PICTURE ON HEADER VIEW RelativeLayout headerView = (RelativeLayout) navigationView.findViewById(R.id.xLayMenuHeader); rlytProfile = (RelativeLayout) navigationView.findViewById(R.id.rlytProfile); mTvUname = (TextView) headerView.findViewById(R.id.xMenuUsrName); mTvUname.setText(AppPrefs.getInstance(CONTEXT_HOME).getUName().toString().toLowerCase() + " " + AppPrefs.getInstance(CONTEXT_HOME).getULastName().toString().toLowerCase()); mIvProfPic = (ImageView) headerView.findViewById(R.id.xIvProfPic); mIvProfPic.setOnClickListener(this); txtProffession = (TextView) headerView.findViewById(R.id.txtProffession); if (StaticUtils.validateString(AppPrefs.getInstance(CONTEXT_HOME).getUProfession().toString().toLowerCase()) && StaticUtils.validateString(AppPrefs.getInstance(CONTEXT_HOME).getUCity().toString().toLowerCase()) && StaticUtils.validateString(AppPrefs.getInstance(CONTEXT_HOME).getUcountry().toString().toLowerCase())) { txtProffession.setText(AppPrefs.getInstance(CONTEXT_HOME).getUProfession().toLowerCase().toString().trim() + ", " + AppPrefs.getInstance(CONTEXT_HOME).getUCity().toLowerCase().toString().trim() + " (" + AppPrefs.getInstance(CONTEXT_HOME).getUcountry().toLowerCase().toString().trim() + ")"); } else if (StaticUtils.validateString(AppPrefs.getInstance(CONTEXT_HOME).getUProfession().toString().toLowerCase()) && StaticUtils.validateString(AppPrefs.getInstance(CONTEXT_HOME).getUCity().toString().toLowerCase())) { txtProffession.setText(AppPrefs.getInstance(CONTEXT_HOME).getUProfession().toString().toLowerCase() + ", " + AppPrefs.getInstance(CONTEXT_HOME).getUCity().toString().toLowerCase()); } else if (StaticUtils.validateString(AppPrefs.getInstance(CONTEXT_HOME).getUProfession().toString().toLowerCase())) { txtProffession.setText(AppPrefs.getInstance(CONTEXT_HOME).getUProfession().toString().toLowerCase()); } else { txtProffession.setText(AppPrefs.getInstance(CONTEXT_HOME).getUstate().toString().toLowerCase()); } if (AppPrefs.getInstance(CONTEXT_HOME).getProfilePic().equalsIgnoreCase("")) { mIvProfPic.setImageDrawable(ContextCompat.getDrawable(CONTEXT_HOME, R.mipmap.profile_view_defaul)); } else { Log.e("PROFILE", "HOME_PROFILE" + AppPrefs.getInstance(CONTEXT_HOME).getProfilePic()); Glide.with(CONTEXT_HOME) .load(AppPrefs.getInstance(CONTEXT_HOME).getProfilePic()) .diskCacheStrategy(DiskCacheStrategy.SOURCE) .into(mIvProfPic); } txtEditProfile = (TextView) headerView.findViewById(R.id.txtEditProfile); txtEditProfile.setOnClickListener(this); //++++++++++++++++******************************* SETUP DRAWER MENU ***************************************** String[] arrMenuNames = getResources().getStringArray(R.array.menu_items); int[] arrMenuIcons = { R.mipmap.topstories, R.mipmap.community, R.mipmap.polls, R.mipmap.celebrations, R.mipmap.interests, R.mipmap.inbox, R.mipmap.feedback, }; mArrMenuItems = new ArrayList<>(); for (int i = 0; i < 7; i++) { CustomMenuItem item = new CustomMenuItem(); item.setId(i); item.setName(arrMenuNames[i]); item.setIcon(arrMenuIcons[i]); mArrMenuItems.add(item); } RecyclerView recViewMenu = (RecyclerView) findViewById(R.id.lst_menu_items); mAdapterMenu = new MyAdapter(CONTEXT_HOME, mArrMenuItems); setupMenuRecyclerView(recViewMenu); String from = ""; String title = ""; if (getIntent() != null) { if (getIntent().getStringExtra("from") != null) { from = getIntent().getStringExtra("from"); try { if (from.equalsIgnoreCase("notif_chat")) { mReplaceFragment(new ChatGroupListFragment(), null); mAdapterMenu.setSelection(1); mAdapterMenu.notifyDataSetChanged(); } // Manisha else if (from.equalsIgnoreCase("notif_birthdaywish")) { Bundle b = new Bundle(); mBtnSearch.setVisibility(View.INVISIBLE); mBtnSearch.setClickable(false); txtEdit.setVisibility(View.GONE); txtEdit.setClickable(true); title = getString(R.string.inbox); mReplaceFragment(new InboxFragment(), b); mAdapterMenu.setSelection(5); mAdapterMenu.notifyDataSetChanged(); } else if (from.equalsIgnoreCase("notif_follow")) { Bundle b = new Bundle(); mBtnSearch.setVisibility(View.INVISIBLE); mBtnSearch.setClickable(false); txtEdit.setVisibility(View.GONE); txtEdit.setClickable(true); title = getString(R.string.inbox); mReplaceFragment(new InboxFragment(), b); mAdapterMenu.setSelection(5); mAdapterMenu.notifyDataSetChanged(); } else if (from.equalsIgnoreCase("notif_message")) { Bundle b = new Bundle(); // b.putString("channelid", getIntent().getStringExtra("channelid")); // StaticUtils.printErr("home screen channel id from notif :: " + getIntent().getStringExtra("channelid")); mBtnSearch.setVisibility(View.INVISIBLE); mBtnSearch.setClickable(false); txtEdit.setVisibility(View.GONE); txtEdit.setClickable(true); title = getString(R.string.inbox); mReplaceFragment(new InboxFragment(), b); mAdapterMenu.setSelection(5); mAdapterMenu.notifyDataSetChanged(); } else if (from.equalsIgnoreCase("offline")) { Bundle b = new Bundle(); // b.putString("channelid", getIntent().getStringExtra("channelid")); // StaticUtils.printErr("home screen channel id from notif :: " + getIntent().getStringExtra("channelid"));// mReplaceFragment(new InboxFragment(), b);// mAdapterMenu.setSelection(5);// mAdapterMenu.notifyDataSetChanged(); } else if (from.equalsIgnoreCase("notif_rejectContent")) { Bundle b = new Bundle(); // b.putString("channelid", getIntent().getStringExtra("channelid")); //StaticUtils.printErr("home screen channel id from notif :: " + getIntent().getStringExtra("channelid")); txtEdit.setVisibility(View.GONE); txtEdit.setClickable(false); mBtnSearch.setVisibility(View.VISIBLE); mBtnSearch.setClickable(true); mBtnSearch.setImageResource(R.mipmap.search_icon); mBtnSearch.setColorFilter(Color.parseColor(AppPrefs.getInstance(HomeScreen.this).getOthrCode("os_topheader_text_color"))); // GradientDrawable drawable = (GradientDrawable) mBtnSearch.getBackground();// drawable.setColor(Color.parseColor(AppPrefs.getInstance(HomeScreen.this).getOthrCode("ls_topheader_text_color"))); mBtnSearch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(HomeScreen.this, SearchableActivity.class); startActivity(intent); // startActivity(intent.setClass(HomeScreen.this, PostDetail.class)); // startActivity(i); } }); title = appLabel; mReplaceFragment(new TopStoriesFrag(), null); mAdapterMenu.setSelection(0); mAdapterMenu.notifyDataSetChanged(); } else if (from.equalsIgnoreCase("comments")) { txtEdit.setVisibility(View.GONE); txtEdit.setClickable(false); mBtnSearch.setVisibility(View.VISIBLE); mBtnSearch.setClickable(true); mBtnSearch.setImageResource(R.mipmap.search_icon); mBtnSearch.setColorFilter(Color.parseColor(AppPrefs.getInstance(HomeScreen.this).getOthrCode("os_topheader_text_color"))); // GradientDrawable drawable = (GradientDrawable) mBtnSearch.getBackground();// drawable.setColor(Color.parseColor(AppPrefs.getInstance(HomeScreen.this).getOthrCode("ls_topheader_text_color"))); mBtnSearch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(HomeScreen.this, SearchableActivity.class); startActivity(intent); // startActivity(intent.setClass(HomeScreen.this, PostDetail.class)); // startActivity(i); } }); title = appLabel; mReplaceFragment(new TopStoriesFrag(), null); mAdapterMenu.setSelection(0); mAdapterMenu.notifyDataSetChanged(); } else if (from.equalsIgnoreCase("commented")) { txtEdit.setVisibility(View.GONE); txtEdit.setClickable(false); mBtnSearch.setVisibility(View.VISIBLE); mBtnSearch.setClickable(true); mBtnSearch.setImageResource(R.mipmap.search_icon); mBtnSearch.setColorFilter(Color.parseColor(AppPrefs.getInstance(HomeScreen.this).getOthrCode("os_topheader_text_color"))); // GradientDrawable drawable = (GradientDrawable) mBtnSearch.getBackground();// drawable.setColor(Color.parseColor(AppPrefs.getInstance(HomeScreen.this).getOthrCode("ls_topheader_text_color"))); mBtnSearch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(HomeScreen.this, SearchableActivity.class); startActivity(intent); // startActivity(intent.setClass(HomeScreen.this, PostDetail.class)); // startActivity(i); } }); title = appLabel; mReplaceFragment(new TopStoriesFrag(), null); mAdapterMenu.setSelection(0); mAdapterMenu.notifyDataSetChanged(); } else { // if (from.equalsIgnoreCase("notif_channel")) {// Bundle b = new Bundle();// b.putString("artical_id", getIntent().getStringExtra("artical_id"));// StaticUtils.printErr("home screen channel id from notif :: " + getIntent().getStringExtra("channelid"));// mReplaceFragment(new TopStoriesFrag(), b);// } else txtEdit.setVisibility(View.GONE); txtEdit.setClickable(false); mBtnSearch.setVisibility(View.VISIBLE); mBtnSearch.setClickable(true); mBtnSearch.setImageResource(R.mipmap.search_icon); mBtnSearch.setColorFilter(Color.parseColor(AppPrefs.getInstance(HomeScreen.this).getOthrCode("os_topheader_text_color"))); mReplaceFragment(new TopStoriesFrag(), null); mAdapterMenu.setSelection(0); mAdapterMenu.notifyDataSetChanged(); } } catch (Exception e) { txtEdit.setVisibility(View.GONE); txtEdit.setClickable(false); mBtnSearch.setVisibility(View.VISIBLE); mBtnSearch.setClickable(true); mBtnSearch.setImageResource(R.mipmap.search_icon); mBtnSearch.setColorFilter(Color.parseColor(AppPrefs.getInstance(HomeScreen.this).getOthrCode("os_topheader_text_color"))); mReplaceFragment(new TopStoriesFrag(), null); mAdapterMenu.setSelection(0); mAdapterMenu.notifyDataSetChanged(); } //mTvActionBarTitle.setText(appLabel); DrawerLayout drawer1 = (DrawerLayout) findViewById(R.id.drawer_layout); drawer1.closeDrawer(GravityCompat.START); mTvActionBarTitle.setText(title); mSetTheme(headerView, recViewMenu); } else { txtEdit.setVisibility(View.GONE); txtEdit.setClickable(false); mBtnSearch.setVisibility(View.VISIBLE); mBtnSearch.setClickable(true); mBtnSearch.setImageResource(R.mipmap.search_icon); mBtnSearch.setColorFilter(Color.parseColor(AppPrefs.getInstance(HomeScreen.this).getOthrCode("os_topheader_text_color"))); mReplaceFragment(new TopStoriesFrag(), null); mAdapterMenu.setSelection(0); mAdapterMenu.notifyDataSetChanged(); } } } else StaticUtils.showMsgDialogTitle(this, this.getResources().getString(R.string.no_internet_title), this.getResources().getString(R.string.no_internet_msg)); } @Override public void onStart() { super.onStart(); } private void setupMenuRecyclerView(RecyclerView recyclerView) { recyclerView.setLayoutManager(new LinearLayoutManager(CONTEXT_HOME)); recyclerView.setHasFixedSize(true); recyclerView.setAdapter(mAdapterMenu); recyclerView.addOnItemTouchListener( new RecyclerItemClickListener(CONTEXT_HOME, new RecyclerItemClickListener.OnItemClickListener() { @Override public void onItemClick(View view, int position) { String title = ""; if (position != 7) { mAdapterMenu.setSelection(position); mAdapterMenu.notifyDataSetChanged(); txtEdit.setVisibility(View.GONE); txtEdit.setClickable(false); mBtnSearch.setVisibility(View.GONE); mBtnSearch.setClickable(false); } mSetupFab(false); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); // Handle navigation view item clicks here. if (position == 0) { txtEdit.setVisibility(View.GONE); txtEdit.setClickable(false); mBtnSearch.setVisibility(View.VISIBLE); mBtnSearch.setClickable(true); mBtnSearch.setImageResource(R.mipmap.search_icon); mBtnSearch.setColorFilter(Color.parseColor(AppPrefs.getInstance(HomeScreen.this).getOthrCode("os_topheader_text_color"))); // GradientDrawable drawable = (GradientDrawable) mBtnSearch.getBackground();// drawable.setColor(Color.parseColor(AppPrefs.getInstance(HomeScreen.this).getOthrCode("ls_topheader_text_color"))); mBtnSearch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(HomeScreen.this, SearchableActivity.class); startActivity(intent); // startActivity(intent.setClass(HomeScreen.this, PostDetail.class)); // startActivity(i); } }); AppPrefs.getInstance(HomeScreen.this).setBdayPagerClose("1"); title = appLabel; mReplaceFragment(new TopStoriesFrag(), null); } else if (position == 1) { txtEdit.setVisibility(View.GONE); txtEdit.setClickable(false); mBtnSearch.setVisibility(View.VISIBLE); mBtnSearch.setClickable(true); mBtnSearch.setImageResource(R.mipmap.addcommunity); // mBtnSearch.setImageResource(R.mipmap.remove);// mBtnSearch.setColorFilter(Color.parseColor(AppPrefs.getInstance(mContext).getOthrCode("os_topheader_text_color"))); mBtnSearch.setColorFilter(Color.parseColor(AppPrefs.getInstance(HomeScreen.this).getOthrCode("os_topheader_text_color"))); mBtnSearch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(HomeScreen.this, ChatRoomActivity.class); i.putExtra("from", "create"); startActivity(i); } }); title = getString(R.string.communities); mReplaceFragment(new ChatGroupListFragment(), null); } else if (position == 2) { txtEdit.setVisibility(View.GONE); txtEdit.setClickable(false); mBtnSearch.setVisibility(View.INVISIBLE); mBtnSearch.setClickable(false); title = getString(R.string.polls); mReplaceFragment(new PollsAndSurveyList(), null); } else if (position == 3) { txtEdit.setVisibility(View.GONE); txtEdit.setClickable(false); mBtnSearch.setVisibility(View.INVISIBLE); mBtnSearch.setClickable(false); title = getString(R.string.celebrations); mReplaceFragment(new CelebrationScreen(), null); } else if (position == 4) { txtEdit.setVisibility(View.GONE); txtEdit.setClickable(false); mBtnSearch.setVisibility(View.VISIBLE); mBtnSearch.setClickable(true); mBtnSearch.setImageResource(R.mipmap.round_filter); title = getString(R.string.my_int); mReplaceFragment(new FeedFragment(), null); } else if (position == 5) { mBtnSearch.setVisibility(View.INVISIBLE); mBtnSearch.setClickable(false); txtEdit.setVisibility(View.GONE); txtEdit.setClickable(true); title = getString(R.string.inbox); mReplaceFragment(new InboxFragment(), null); // mLogout(); } else if (position == 6) { mBtnSearch.setVisibility(View.INVISIBLE); mBtnSearch.setClickable(false); txtEdit.setVisibility(View.GONE); txtEdit.setClickable(false); title = getString(R.string.feedback_suggestion); mReplaceFragment(new SuggestionsFeedbackScreen(), null); } mTvActionBarTitle.setText(title); } }) ); } private void mReplaceFragment(Fragment fragment, Bundle b) { mCorrentFragment = fragment; FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); if (b != null) fragment.setArguments(b); transaction.replace(R.id.xContainer, fragment); // transaction.addToBackStack(null); transaction.commit(); } public void mSetupFab(boolean showFab) { try { if (showFab) { FAB_CREATE_ART.setVisibility(View.VISIBLE); CoordinatorLayout.LayoutParams p = (CoordinatorLayout.LayoutParams) FAB_CREATE_ART.getLayoutParams(); p.setBehavior(new ScrollAwareFABBehavior(CONTEXT_HOME)); FAB_CREATE_ART.setLayoutParams(p); FAB_CREATE_ART.hide(); new Handler().postDelayed(new Runnable() { @Override public void run() { FAB_CREATE_ART.show(); } }, 2000); } else { FAB_CREATE_ART.hide(); FAB_CREATE_ART.setVisibility(View.GONE); CoordinatorLayout.LayoutParams p = (CoordinatorLayout.LayoutParams) FAB_CREATE_ART.getLayoutParams(); p.setBehavior(null); FAB_CREATE_ART.setLayoutParams(p); } } catch (Exception e) { e.printStackTrace(); } } public void mUpdateMenuHeader() { Log.e("PROFILE PICTURE", "MENU HEADER :: " + AppPrefs.getInstance(CONTEXT_HOME).getProfilePic()); if (AppPrefs.getInstance(CONTEXT_HOME).getProfilePic().equalsIgnoreCase("")) { mIvProfPic.setImageDrawable(ContextCompat.getDrawable(CONTEXT_HOME, R.mipmap.profile_view_defaul)); } else { Log.e("PROFILE", "HOME_PROFILE" + AppPrefs.getInstance(CONTEXT_HOME).getProfilePic()); Glide.with(CONTEXT_HOME) .load(AppPrefs.getInstance(CONTEXT_HOME).getProfilePic()) .signature(new StringSignature(String.valueOf(System.currentTimeMillis()))) .into(mIvProfPic); } if (StaticUtils.validateString(AppPrefs.getInstance(CONTEXT_HOME).getUProfession().toString().toLowerCase().trim()) && StaticUtils.validateString(AppPrefs.getInstance(CONTEXT_HOME).getUCity()) && StaticUtils.validateString(AppPrefs.getInstance(CONTEXT_HOME).getUcountry().toString().toLowerCase().trim())) { txtProffession.setText(AppPrefs.getInstance(CONTEXT_HOME).getUProfession().toString().toLowerCase().trim() + ", " + AppPrefs.getInstance(CONTEXT_HOME).getUCity().toString().toLowerCase().trim() + " (" + AppPrefs.getInstance(CONTEXT_HOME).getUcountry().toString().toLowerCase().trim() + ")"); } else if (StaticUtils.validateString(AppPrefs.getInstance(CONTEXT_HOME).getUProfession()) && StaticUtils.validateString(AppPrefs.getInstance(CONTEXT_HOME).getUCity().toString().toLowerCase().trim())) { txtProffession.setText(AppPrefs.getInstance(CONTEXT_HOME).getUProfession().toString().toLowerCase().trim() + ", " + AppPrefs.getInstance(CONTEXT_HOME).getUCity().toString().toLowerCase().trim()); } else if (StaticUtils.validateString(AppPrefs.getInstance(CONTEXT_HOME).getUProfession().toString().toLowerCase().trim())) { txtProffession.setText(AppPrefs.getInstance(CONTEXT_HOME).getUProfession().toString().toLowerCase().trim()); } else { txtProffession.setText(AppPrefs.getInstance(CONTEXT_HOME).getUstate().toString().toLowerCase().trim()); } } @Override public void onPause() { super.onPause(); isActivityPaused = true; } @Override public void onResume() { super.onResume(); isActivityPaused = false; LocalBroadcastManager.getInstance(HomeScreen.this).registerReceiver(receiver, new IntentFilter(BROADCAST_ACTION)); if (FLAG_PROF_UPDATED) new GetProfileInfo().execute(); // mUpdateMenuHeader(); } //******************************* DRAWER FUNCTIONS ************************************************** @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.home_screen, menu); MenuItem settings = menu.findItem(R.id.action_settings); settings.setVisible(false); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); return id == R.id.action_settings || super.onOptionsItemSelected(item); } private void mLogout() { new MaterialDialog.Builder(this) .title(R.string.logout_title) .content(R.string.logout_msg) .positiveColor(Color.parseColor(AppPrefs.getInstance(HomeScreen.this).getOthrCode("os_send_btn_text_color"))) .negativeColor(Color.parseColor(AppPrefs.getInstance(HomeScreen.this).getOthrCode("os_cancel_btn_text_color"))) .positiveText(R.string.btn_yes) .onPositive(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(MaterialDialog materialDialog, DialogAction dialogAction) { materialDialog.dismiss(); Intent toLogin = new Intent(HomeScreen.this, LoginRegisterScreen.class); DatabaseHandler dbHandle = DatabaseHandler.getInstance(HomeScreen.this); dbHandle.sDeleteTable("user_profile"); dbHandle.close(); AppPrefs.getInstance(CONTEXT_HOME).saveLogin(false); AppPrefs.getInstance(CONTEXT_HOME).saveSynctimeData(""); AppPrefs.getInstance(CONTEXT_HOME).saveProfilePic(""); AppPrefs.getInstance(CONTEXT_HOME).saveChatUsername(""); AppPrefs.getInstance(CONTEXT_HOME).saveUid(""); startActivity(toLogin); HomeScreen.this.finish(); /*if (GoScoop.getInstance(HomeScreen.this).getXmppConn() != null) ChatUtils.disconnect(GoScoop.getInstance(HomeScreen.this).getXmppConn());*/ } }) .negativeText(R.string.btn_cncl) .onNegative(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(MaterialDialog materialDialog, DialogAction dialogAction) { materialDialog.dismiss(); } }) .autoDismiss(false) .show(); } @Override public void onTaskComplete(Object result) { mGetJoinedRooms(); } private void mGetJoinedRooms() { RestClient.getChatWsClient().getJoinedRooms(AppPrefs.getInstance(getApplicationContext()).getAuthCode(), AppPrefs.getInstance(getApplicationContext()).getOrgid(), AppPrefs.getInstance(getApplicationContext()).getChatUsername() + "@" + AppPrefs.getInstance(getApplicationContext()).getHostName(), new Callback<JoinedRooms>() { @Override public void success(JoinedRooms example, Response response) { try { /*if (example.getStatus().equalsIgnoreCase("1")) { for (int i = 0; i < example.getData().size(); i++) ChatUtils.joinRoom(getApplicationContext(), example.getData().get(i).getName()); } else if (example.getStatus().equalsIgnoreCase("-1")) { } else if (example.getStatus().equalsIgnoreCase("0")) { } else { }*/ } catch (Exception e) { e.printStackTrace(); } } @Override public void failure(RetrofitError retrofitError) { } }); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.txtLogout: mLogout(); break; case R.id.imgPoweredBy: displayTerms(); break; case R.id.lytContact: displayTerms(); break; case R.id.txtEditProfile: Log.e("", ""); ((ImageView) this.findViewById(R.id.xBtnSearch)).setVisibility(View.GONE); ((TextView) this.findViewById(R.id.txtEdit)).setVisibility(View.GONE); txtEdit.setVisibility(View.GONE); mBtnSearch.setVisibility(View.INVISIBLE); mBtnSearch.setClickable(false); mBtnSearch.setVisibility(View.INVISIBLE); AppPrefs.getInstance(CONTEXT_HOME).saveUPdateProfileState("editprofile"); mTvActionBarTitle.setText(getString(R.string.dashboard)); // mBtnSearch.setVisibility(View.INVISIBLE); Handler handler1 = new Handler(); handler1.postDelayed(new Runnable() { @Override public void run() { DrawerLayout drawer1 = (DrawerLayout) findViewById(R.id.drawer_layout); drawer1.closeDrawer(GravityCompat.START); mAdapterMenu.setSelection(-1); mAdapterMenu.notifyDataSetChanged(); } }, 400); new GetProfileInfo().execute(); // mSetupFab(false);// mReplaceFragment(new FragmentDashboardProfile(), null);// // update selected item and title, then close the drawer// DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);// drawer.closeDrawer(GravityCompat.START);// mAdapterMenu.setSelection(-1);// mAdapterMenu.notifyDataSetChanged();// if (!FLAG_PROF_UPDATED)// FLAG_PROF_UPDATED = false; break; case R.id.xIvProfPic: txtEdit.setVisibility(View.GONE); mBtnSearch.setVisibility(View.INVISIBLE); mBtnSearch.setClickable(false); mBtnSearch.setVisibility(View.INVISIBLE); AppPrefs.getInstance(CONTEXT_HOME).saveUPdateProfileState("propic"); mTvActionBarTitle.setText(getString(R.string.dashboard)); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); mAdapterMenu.setSelection(-1); mAdapterMenu.notifyDataSetChanged(); } }, 400); // mBtnSearch.setVisibility(View.INVISIBLE); new GetProfileInfo().execute(); // mSetupFab(false); break; } } public void displayTerms() { txtEdit.setVisibility(View.INVISIBLE); mBtnSearch.setVisibility(View.INVISIBLE); mBtnSearch.setClickable(false); mTvActionBarTitle.setText(getString(R.string.about_astrum)); mTvActionBarTitle.setGravity(Gravity.CENTER); mSetupFab(false); mReplaceFragment(new AboutUsFragment(), null); // update selected item and title, then close the drawer DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); mAdapterMenu.setSelection(-1); mAdapterMenu.notifyDataSetChanged(); } //******************************* DRAWER FUNCTIONS ************************************************** private class GetProfileInfo extends AsyncTask<String, Void, String> { private String mEmpCode, mFName, mLName, mEmail, mMob, mCntryCode, mAbout, mWebsite, mDept, mGen, mMrtlStat, mBg, mDob, mDoj, mPcNum, mNat, mAddr1, mAddr2, mCity, mState, mDesig, mDtCrtd, mPostcode, mOrg, mImg, mHobbies, mSpouseName, mDomrg, mUser_secondary_email, mUser_expertise, mUser_country, mUser_is_profile, mUser_last_update; @Override protected void onPreExecute() { super.onPreExecute(); getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE); } @Override protected String doInBackground(String... params) { String res = ""; DatabaseHandler dbHandle = DatabaseHandler.getInstance(HomeScreen.this); Cursor mCur = dbHandle.sGetTableData("user_profile"); try { if (mCur.getCount() > 0) { mCur.moveToFirst(); mEmpCode = mCur.getString(mCur.getColumnIndex("_emp_code_user")); mFName = mCur.getString(mCur.getColumnIndex("_fname_user")); mLName = mCur.getString(mCur.getColumnIndex("_lname_user")); mEmail = mCur.getString(mCur.getColumnIndex("_email_user")); mMob = mCur.getString(mCur.getColumnIndex("_mob_user")); mCntryCode = mCur.getString(mCur.getColumnIndex("_country_code_user")); mAbout = mCur.getString(mCur.getColumnIndex("_about_user")); mWebsite = mCur.getString(mCur.getColumnIndex("_website_user")); mDept = mCur.getString(mCur.getColumnIndex("_dept_user")); mGen = mCur.getString(mCur.getColumnIndex("_gender_user")); mMrtlStat = mCur.getString(mCur.getColumnIndex("_marital_stat_user")); mBg = mCur.getString(mCur.getColumnIndex("_bg_user")); mDob = mCur.getString(mCur.getColumnIndex("_dob_user")); mDoj = mCur.getString(mCur.getColumnIndex("_doj_user")); mPcNum = mCur.getString(mCur.getColumnIndex("_pcard_user")); mNat = mCur.getString(mCur.getColumnIndex("_nationality_user")); mAddr1 = mCur.getString(mCur.getColumnIndex("_addr1_user")); mAddr2 = mCur.getString(mCur.getColumnIndex("_addr2_user")); mCity = mCur.getString(mCur.getColumnIndex("_city_user")); mState = mCur.getString(mCur.getColumnIndex("_state_user")); mDesig = mCur.getString(mCur.getColumnIndex("_desig_user")); mPostcode = mCur.getString(mCur.getColumnIndex("_postcode_user")); mOrg = mCur.getString(mCur.getColumnIndex("_org_name_user")); mImg = mCur.getString(mCur.getColumnIndex("_img_url_user")); mWebsite = mCur.getString(mCur.getColumnIndex("_website_user")); mHobbies = mCur.getString(mCur.getColumnIndex("_hobbies_user")); mDtCrtd = mCur.getString(mCur.getColumnIndex("_crtd_dt_user")); mSpouseName = mCur.getString(mCur.getColumnIndex("_spouse_name_user")); mDomrg = mCur.getString(mCur.getColumnIndex("_dom_user")); mUser_secondary_email = mCur.getString(mCur.getColumnIndex("user_secondary_email")); mUser_expertise = mCur.getString(mCur.getColumnIndex("user_expertise")); mUser_country = mCur.getString(mCur.getColumnIndex("user_country")); mUser_is_profile = mCur.getString(mCur.getColumnIndex("user_is_profile")); mUser_last_update = mCur.getString(mCur.getColumnIndex("user_last_update")); res = "success"; } else { res = "no_data"; } } catch (Exception e) { e.printStackTrace(); res = "error"; } mCur.close(); return res; } @Override protected void onPostExecute(String result) { getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE); if (result.equalsIgnoreCase("success")) { Bundle bundle = new Bundle(); bundle.putString("emp_code", mEmpCode); bundle.putString("fname", mFName); bundle.putString("lname", mLName); bundle.putString("email", mEmail); bundle.putString("mob", mMob); bundle.putString("cntryCode", mCntryCode); bundle.putString("dept", mDept); bundle.putString("gen", mGen); bundle.putString("marital", mMrtlStat); bundle.putString("bloodg", mBg); bundle.putString("dob", mDob); bundle.putString("doj", mDoj); bundle.putString("pcnum", mPcNum); bundle.putString("nat", mNat); bundle.putString("addr1", mAddr1); bundle.putString("addr2", mAddr2); bundle.putString("city", mCity); bundle.putString("state", mState); bundle.putString("postcode", mPostcode); bundle.putString("org", mOrg); bundle.putString("website", mWebsite); bundle.putString("hobbies", mHobbies); bundle.putString("about", mAbout); bundle.putString("desig", mDesig); bundle.putString("dt_crtd", mDtCrtd); bundle.putString("spouse_name", mSpouseName); bundle.putString("domrg", mDomrg); bundle.putString("secondaryemail", mUser_secondary_email); bundle.putString("expertise", mUser_expertise); bundle.putString("country", mUser_country); bundle.putString("is_profile", mUser_is_profile); bundle.putString("last_update", mUser_last_update); bundle.putString("mImg", mImg); mSetupFab(false); // txtProffession.setText("" + mDesig.toLowerCase().toString() + ", " + mState.toLowerCase().toString()); mBtnSearch.setVisibility(View.VISIBLE); mBtnSearch.setClickable(true); // mBtnSearch.setImageResource(R.mipmap.recent_act);// mBtnSearch.setOnClickListener(new View.OnClickListener() {// @Override// public void onClick(View v) {// Intent i = new Intent(HomeScreen.this, RecentActivities.class);// startActivity(i);// }// });// if (progressDialog.isShowing() && progressDialog != null)// progressDialog.dismiss();// mUpdateMenuHeader(); // update selected item and title, then close the drawer mReplaceFragment(new FragmentDashboardProfile(), bundle); if (!FLAG_PROF_UPDATED) FLAG_PROF_UPDATED = false; } } } //******************************************************************************************************** private void mSetTheme(View headerView, View recViewMenu) { try { getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor(AppPrefs.getInstance(HomeScreen.this).getOthrCode("ls_topheader_bg_color")))); } catch (Exception e) { e.printStackTrace(); } mTvActionBarTitle.setTextColor(Color.parseColor(AppPrefs.getInstance(HomeScreen.this).getOthrCode("ls_topheader_text_color"))); rlytProfile.setBackground(new ColorDrawable(Color.parseColor(AppPrefs.getInstance(HomeScreen.this).getOthrCode("ls_topheader_bg_color")))); headerView.setBackground(new ColorDrawable(Color.parseColor(AppPrefs.getInstance(HomeScreen.this).getOthrCode("left_menu_bg_color")))); recViewMenu.setBackground(new ColorDrawable(Color.parseColor(AppPrefs.getInstance(HomeScreen.this).getOthrCode("left_menu_bg_color")))); mNegBtnClr = "#8b8b8b";//mCur.getString(mCur.getColumnIndex("popuperrorbtnbgcolor")); mClrMenuItems = AppPrefs.getInstance(HomeScreen.this).getOthrCode("left_menu_text_color"); mClrMenuItemSel = AppPrefs.getInstance(HomeScreen.this).getOthrCode("os_topheader_bg_color"); mClrInner = AppPrefs.getInstance(HomeScreen.this).getOthrCode("left_menu_bg_color"); mTvPoweredBy.setTextColor(Color.parseColor(AppPrefs.getInstance(HomeScreen.this).getOthrCode("left_menu_bg_color"))); mTvGoscoop.setTextColor(Color.parseColor(AppPrefs.getInstance(HomeScreen.this).getOthrCode("left_menu_bg_color"))); txtLogout.setTextColor(Color.parseColor(AppPrefs.getInstance(HomeScreen.this).getOthrCode("left_menu_bg_color"))); GradientDrawable drawable = (GradientDrawable) txtLogout.getBackground(); drawable.setStroke(2, Color.parseColor(AppPrefs.getInstance(this).getOthrCode("left_menu_bg_color"))); mTvUname.setTextColor(Color.parseColor(AppPrefs.getInstance(HomeScreen.this).getOthrCode("os_topheader_text_color"))); txtProffession.setTextColor(Color.parseColor(AppPrefs.getInstance(HomeScreen.this).getOthrCode("os_topheader_text_color"))); txtEditProfile.setTextColor(Color.parseColor(AppPrefs.getInstance(HomeScreen.this).getOthrCode("left_menu_selected_text_color"))); GradientDrawable drawable2 = (GradientDrawable) txtEditProfile.getBackground(); drawable2.setColor(Color.parseColor(AppPrefs.getInstance(this).getOthrCode("ls_topheader_text_color"))); drawable2.setStroke(2, Color.parseColor(AppPrefs.getInstance(this).getOthrCode("left_menu_selected_text_color"))); mPosBtnClr = AppPrefs.getInstance(HomeScreen.this).getOthrCode("left_menu_bg_color"); } private void mClearStaticValues() { if (StaticUtils.CROPPED_BITMAP != null) StaticUtils.CROPPED_BITMAP = null; StaticUtils.IMAGE_URI = null; StaticUtils.BTN_OK_CLICKED = false; } @Override protected void onDestroy() { super.onDestroy(); onDetachedFromWindow(); LocalBroadcastManager.getInstance(HomeScreen.this).unregisterReceiver(receiver); // stopService(mService); } private void mSendUpdatedDate() { RestClient.get().sendLastUpdatedDate(AppPrefs.getInstance(this).getUid(), AppPrefs.getInstance(this).getOrgid(), new Callback<Response>() { @Override public void success(Response response, Response response2) { BufferedReader reader = null; String strResponse = ""; try { reader = new BufferedReader(new InputStreamReader(response.getBody().in())); String a = null; while ((a = reader.readLine()) != null) { strResponse = strResponse + a; } } catch (IOException e) { e.printStackTrace(); } Log.e("SUCCESS RESPONSE", strResponse); try { JSONObject mJsonObject = new JSONObject(strResponse); String strStatus = mJsonObject.getString("status"); if (strStatus.equalsIgnoreCase("1")) { } } catch (JSONException e) { e.printStackTrace(); } } @Override public void failure(RetrofitError retrofitError) { getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE); } }); } @Override public void onBackPressed() { mClearStaticValues(); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); if (drawer.isDrawerOpen(GravityCompat.START)) { drawer.closeDrawer(GravityCompat.START); } else { try { StaticUtils.printErr("backstack entry :: " + getFragmentManager().findFragmentByTag(CelebrationScreen.WISHFRAG)); } catch (Exception e) { e.printStackTrace(); } if (doubleBackToExitPressedOnce) { finish(); // super.onBackPressed(); return; } this.doubleBackToExitPressedOnce = true; // StaticUtils.showMsgDialogTitle(this,getResources().getString(R.string.title_exit),getResources().getString(R.string.exit_msg));// StaticUtils.mShowToast(mRelLayHomeScree, getString(R.string.exit_msg), Snackbar.LENGTH_SHORT); new Handler().postDelayed(new Runnable() { @Override public void run() { doubleBackToExitPressedOnce = false; } }, 2000); } } public void showMsgDialogTitle(Context context, final String title, final String text) { new MaterialDialog.Builder(context) .title(title) .content(text) // .positiveColor(Color.parseColor(mPosBtnClr)) .positiveText(R.string.btn_ok) .onPositive(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(MaterialDialog materialDialog, DialogAction dialogAction) { materialDialog.dismiss(); } }) .autoDismiss(false) .show(); } public static final String BROADCAST_ACTION = "NotifyInbox"; private BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { boolean notify = intent.getBooleanExtra("notify_count", false); Log.e("notify_count ", "" + notify); if (notify) { mAdapterMenu.notifyDataSetChanged(); } } }; }
2)MyAdapter.java
package com.credencys.goscoop.custommenu; import android.content.Context; import android.graphics.Color; import android.graphics.drawable.GradientDrawable; import android.support.v4.content.ContextCompat; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.util.TypedValue; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import com.credencys.goscoop.R; import com.credencys.goscoop.activities.HomeScreen; import com.credencys.goscoop.utils.AppPrefs; import java.util.ArrayList; import java.util.List; /** * Created by Maitrey on 12/21/2015. */public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> { private final TypedValue mTypedValue = new TypedValue(); private int mBackground; private List<CustomMenuItem> mValues; private int selectedPosition; private Context con; public static class ViewHolder extends RecyclerView.ViewHolder { public CustomMenuItem mBoundString; public final LinearLayout mView; public final ImageView mIcon; public ImageView imgArrow; public final TextView mTvName,xTvCount; public ViewHolder(View view) { super(view); mView = (LinearLayout) view.findViewById(R.id.xLinLayMenuItem); mView.setClickable(true); // mSep = (LinearLayout) view.findViewById(R.id.xSepMenu); mTvName = (TextView) view.findViewById(R.id.xTvCamera); mIcon = (ImageView) view.findViewById(R.id.xIconOne); imgArrow = (ImageView) view.findViewById(R.id.imgArrow); xTvCount = (TextView)view.findViewById(R.id.xTvCount); } @Override public String toString() { return super.toString() + " '" + mTvName.getText(); } } public CustomMenuItem getValueAt(int position) { return mValues.get(position); } public MyAdapter(Context context, List<CustomMenuItem> items) { context.getTheme().resolveAttribute(R.attr.selectableItemBackground, mTypedValue, true); this.con = context; mBackground = mTypedValue.resourceId; mValues = new ArrayList<>(items); } @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(parent.getContext()) .inflate(R.layout.menu_list_item, parent, false); view.setBackgroundResource(mBackground); return new ViewHolder(view); } @Override public void onBindViewHolder(final ViewHolder holder, int position) { holder.mBoundString = mValues.get(position); holder.mTvName.setText(mValues.get(position).getName()); holder.mIcon.setImageResource(mValues.get(position).getIcon()); holder.imgArrow.setImageResource(R.mipmap.arrow); holder.xTvCount.setTextColor(Color.parseColor(AppPrefs.getInstance(con).getOthrCode("ls_topheader_text_color"))); // GradientDrawable drawable = (GradientDrawable) holder.xTvCount.getBackground();// drawable.setColor(Color.parseColor(AppPrefs.getInstance(con).getOthrCode("left_menu_selected_text_color"))); if (position == 5){ holder.xTvCount.setVisibility(View.VISIBLE); int count = AppPrefs.getInstance(con).getInboxCount(); if(count > 0) { holder.xTvCount.setVisibility(View.VISIBLE); if(count < 10){ holder.xTvCount.setText(String.valueOf(" "+count+" ")); }else{ holder.xTvCount.setText(String.valueOf(count)); } }else{ holder.xTvCount.setVisibility(View.GONE); } }else{ holder.xTvCount.setVisibility(View.GONE); } if(position == selectedPosition) { holder.mTvName.setTextColor(Color.parseColor(HomeScreen.mClrMenuItemSel)); holder.imgArrow.setColorFilter(Color.parseColor(AppPrefs.getInstance(con).getOthrCode("left_menu_selected_text_color"))); // holder.mView.setBackground(ContextCompat.getDrawable(con, R.drawable.menu_selector)); holder.mIcon.setColorFilter(Color.parseColor(AppPrefs.getInstance(con).getOthrCode("left_menu_selected_text_color"))); holder.mTvName.setTextColor(Color.parseColor(AppPrefs.getInstance(con).getOthrCode("left_menu_selected_text_color"))); // holder.mSep.setVisibility(View.GONE); } else { // holder.mSep.setVisibility(View.VISIBLE); holder.mTvName.setTextColor(Color.parseColor(HomeScreen.mClrMenuItems)); // holder.mView.setBackgroundColor(Color.parseColor(HomeScreen.mClrInner)); holder.imgArrow.setColorFilter(Color.parseColor(AppPrefs.getInstance(con).getOthrCode("left_menu_text_color"))); holder.mIcon.setColorFilter(Color.parseColor(AppPrefs.getInstance(con).getOthrCode("left_menu_text_color"))); holder.mTvName.setTextColor(Color.parseColor(AppPrefs.getInstance(con).getOthrCode("left_menu_text_color"))); } } @Override public int getItemCount() { return mValues.size(); } public void setSelection(int pos) { selectedPosition = pos; } public void setItemSelected(int pos) { selectedPosition = pos; } public void clearSelections() { notifyDataSetChanged(); } }
No comments:
Post a Comment