Instantly share code, notes, and snippets.
Created
November 15, 2018 07:30
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
-
Save NerdFaisal404/a76647fc2050a77d84ae4d230ad12b82 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.audacityit.jigglemed.ui.navigation; | |
| import android.app.Activity; | |
| import android.content.Intent; | |
| import android.content.SharedPreferences; | |
| import android.graphics.Bitmap; | |
| import android.os.Bundle; | |
| import android.os.Handler; | |
| import android.support.annotation.ColorRes; | |
| import android.support.v4.app.Fragment; | |
| import android.support.v4.content.ContextCompat; | |
| import android.support.v7.app.AppCompatActivity; | |
| import android.util.Log; | |
| import android.widget.Toast; | |
| import com.audacityit.jigglemed.Constants; | |
| import com.audacityit.jigglemed.JiggleApplication; | |
| import com.audacityit.jigglemed.R; | |
| import com.audacityit.jigglemed.SharedPreferenceManager; | |
| import com.audacityit.jigglemed.UniqueStack; | |
| import com.audacityit.jigglemed.UtilsJiggle; | |
| import com.audacityit.jigglemed.ui.navigation.chat.eventservice.EventListener; | |
| import com.audacityit.jigglemed.ui.navigation.chat.eventservice.EventService; | |
| import com.audacityit.jigglemed.ui.navigation.chat.eventservice.EventServiceImpl; | |
| import com.audacityit.jigglemed.ui.navigation.connections.views.ConnectionListFragment; | |
| import com.audacityit.jigglemed.ui.navigation.connections.views.ConnectionsFragment; | |
| import com.audacityit.jigglemed.ui.navigation.connections.views.ImportContactsFragment; | |
| import com.audacityit.jigglemed.ui.navigation.connections.views.UsersConnectionFragment; | |
| import com.audacityit.jigglemed.ui.navigation.container.ContainerFragment; | |
| import com.audacityit.jigglemed.ui.navigation.forum.model.UserProfileModel; | |
| import com.audacityit.jigglemed.ui.navigation.forum.views.ForumFragment; | |
| import com.audacityit.jigglemed.ui.navigation.home.HomeFragment; | |
| import com.audacityit.jigglemed.ui.navigation.inbox.InboxFragment; | |
| import com.audacityit.jigglemed.ui.navigation.media.views.MediaFragment; | |
| import com.audacityit.jigglemed.ui.search.SearchActivity; | |
| import com.audacityit.jigglemed.ui.splash.model.LoginInfo; | |
| import com.audacityit.jigglemed.ui.splash.model.LoginRP; | |
| import com.audacityit.jigglemed.ui.userprofile.UserProfileActivity; | |
| import com.audacityit.jigglemed.ui_component.NonSwipeableViewPager; | |
| import com.aurelhubert.ahbottomnavigation.AHBottomNavigation; | |
| import com.aurelhubert.ahbottomnavigation.AHBottomNavigationAdapter; | |
| import com.github.pwittchen.reactivenetwork.library.rx2.ReactiveNetwork; | |
| import com.google.gson.Gson; | |
| import com.google.gson.reflect.TypeToken; | |
| import com.mindorks.nybus.NYBus; | |
| import com.mindorks.nybus.annotation.Subscribe; | |
| import com.mindorks.nybus.event.Channel; | |
| import com.theartofdev.edmodo.cropper.CropImage; | |
| import net.alhazmy13.mediapicker.Video.VideoPicker; | |
| import org.json.JSONException; | |
| import org.json.JSONObject; | |
| import java.lang.reflect.Type; | |
| import java.net.URISyntaxException; | |
| import java.util.ArrayList; | |
| import java.util.HashMap; | |
| import java.util.List; | |
| import butterknife.BindView; | |
| import butterknife.ButterKnife; | |
| import io.reactivex.android.schedulers.AndroidSchedulers; | |
| import io.reactivex.disposables.Disposable; | |
| import io.reactivex.functions.Consumer; | |
| import io.reactivex.schedulers.Schedulers; | |
| import static com.audacityit.jigglemed.UtilsJiggle.googleAnalytics; | |
| public class NavigationActivity extends AppCompatActivity implements NavigationContract.View, EventListener { | |
| public static final int REQUEST_CODE = 99; | |
| private static final String TAG = "NavigationActivity"; | |
| private static EventService mEventService; | |
| PagerAdapter mPagerAdapter; | |
| AHBottomNavigationAdapter mAHBottomNavigationAdapter; | |
| int tabPosition = 0; | |
| String pushtype, lasttime = ""; | |
| boolean doubleBackToExitPressedOnce = false; | |
| UniqueStack bottomNavigationStack; | |
| NavigationContract.Presenter presenter; | |
| String title; | |
| boolean isThereResultFromPreviousActivity = false; | |
| boolean isRunning = false; | |
| OnImageUrlLoadedListener listener; | |
| LoginInfo loginInfo; | |
| Disposable disposable; | |
| boolean dataLoaded; | |
| String forumId; | |
| Disposable navigateToFragmentDisposable; | |
| @BindView(R.id.viewPager) | |
| NonSwipeableViewPager viewPager; | |
| @BindView(R.id.bottom_navigation) | |
| AHBottomNavigation bottomNavigation; | |
| int count = SharedPreferenceManager.getInstance().getInt(Constants.SharedPreferenceKey.INBOX_BADGE); | |
| SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() { | |
| public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { | |
| if (key.equals(Constants.SharedPreferenceKey.NOTIFICATION_BADGE_COUNT)) { | |
| int count = Integer.parseInt(SharedPreferenceManager.getInstance().getString(Constants.SharedPreferenceKey.NOTIFICATION_BADGE_COUNT)); | |
| Log.d(TAG, "onSharedPreferenceChanged:badge " + count); | |
| if(count>0) | |
| bottomNavigation.setNotification(SharedPreferenceManager.getInstance().getString(Constants.SharedPreferenceKey.NOTIFICATION_BADGE_COUNT), 3); | |
| else | |
| bottomNavigation.setNotification("", 3); | |
| } | |
| else if (key.equals(Constants.SharedPreferenceKey.USER_ID_MSG_COUNT)) { | |
| Log.d(TAG, "onSharedPreferenceChanged:id "); | |
| getIds(); | |
| } | |
| } | |
| }; | |
| private HashMap<String, Integer> mFromIds = new HashMap<>(); | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_navigation); | |
| ButterKnife.bind(this); | |
| googleAnalytics(getApplication(), "Navigation"); | |
| bottomNavigationStack = new UniqueStack(); | |
| Log.e(TAG, "onCreate: HomeFragment"); | |
| Intent intent = getIntent(); | |
| pushtype = intent.getStringExtra(Constants.PUSH_TYPE); | |
| Log.d(TAG, "onCreate:pushtype " + pushtype); | |
| if (pushtype != null) { | |
| if (pushtype.equalsIgnoreCase(Constants.NOTIFICATION_TYPE_FORUM)) { | |
| Log.d(TAG, "notificationtray TRUE: "); | |
| ForumFragment.FROM_NOTIFICATION_TRAY = true; | |
| } else { | |
| Log.d(TAG, "notificationtray false: "); | |
| ForumFragment.FROM_NOTIFICATION_TRAY = false; | |
| } | |
| } | |
| socketInitialization(); | |
| initPagerAdapter(); | |
| getIds(); | |
| } | |
| private void getIds() { | |
| String ids = SharedPreferenceManager.getInstance().getString(Constants.SharedPreferenceKey.USER_ID_MSG_COUNT); | |
| Type listType = new TypeToken<HashMap<String, Integer>>() { | |
| }.getType(); | |
| mFromIds = new Gson().fromJson(ids, listType); | |
| } | |
| private void initPagerAdapter() { | |
| mPagerAdapter = new PagerAdapter(getSupportFragmentManager()); | |
| // increase this limit if you have more tabs! | |
| viewPager.setOffscreenPageLimit(3); | |
| viewPager.setAdapter(mPagerAdapter); | |
| initBottomNavigationView(); | |
| } | |
| private void socketInitialization() { | |
| //((JiggleApplication)getApplication()).socketInitialization(); | |
| mEventService = EventServiceImpl.getInstance(); | |
| mEventService.setEventListener(this, this); | |
| // LUC:: | |
| try { | |
| mEventService.connect(getApplicationContext()); | |
| }catch(URISyntaxException e){ | |
| } | |
| } | |
| private void initBottomNavigationView() { | |
| mAHBottomNavigationAdapter = new AHBottomNavigationAdapter(this, R.menu.tab_title); | |
| mAHBottomNavigationAdapter.setupWithBottomNavigation(bottomNavigation); | |
| bottomNavigation.setDefaultBackgroundColor(fetchColor(R.color.colorWhite)); | |
| bottomNavigation.setAccentColor(fetchColor(R.color.colorTabSelected)); | |
| bottomNavigation.setInactiveColor(fetchColor(R.color.colorTabDeselect)); | |
| // Use colored navigation with circle reveal effect | |
| bottomNavigation.setColored(false); | |
| // Manage titles | |
| bottomNavigation.setTitleState(AHBottomNavigation.TitleState.ALWAYS_SHOW); | |
| bottomNavigation.setTitleTextSizeInSp(10, 10); | |
| // Disable the translation inside the CoordinatorLayout | |
| bottomNavigation.setBehaviorTranslationEnabled(false); | |
| bottomNavigation.setTranslucentNavigationEnabled(true); | |
| // Set current item programmatically | |
| /* navigateToFragmentDisposable = Observable.timer(600, TimeUnit.MILLISECONDS) | |
| .subscribeOn(Schedulers.io()) | |
| .observeOn(AndroidSchedulers.mainThread()) | |
| .subscribe(this::onComplete);*/ | |
| new Handler().postDelayed(new Runnable() { | |
| @Override | |
| public void run() { | |
| onComplete(); | |
| } | |
| }, 300); | |
| bottomNavigationStack.add(0); | |
| bottomNavigation.setOnTabSelectedListener(new AHBottomNavigation.OnTabSelectedListener() { | |
| @Override | |
| public boolean onTabSelected(int position, boolean wasSelected) { | |
| if (position == 3) { | |
| } | |
| viewPager.setCurrentItem(position); | |
| tabPosition = position; | |
| bottomNavigationStack.add(position); // added to backStack | |
| UtilsJiggle.hideSoftKeyboard(NavigationActivity.this); | |
| return true; | |
| } | |
| }); | |
| } | |
| private int fetchColor(@ColorRes int color) { | |
| return ContextCompat.getColor(this, color); | |
| } | |
| private void onComplete() { | |
| Log.d(TAG, "navigate : "); | |
| if (pushtype != null) { | |
| if (pushtype.equalsIgnoreCase(Constants.NOTIFICATION_TYPE_CHAT)) { | |
| bottomNavigation.setCurrentItem(3); | |
| viewPager.setCurrentItem(3); | |
| tabPosition = 3; | |
| } else if (pushtype.equalsIgnoreCase(Constants.NOTIFICATION_TYPE_CONNECTION)) { | |
| bottomNavigation.setCurrentItem(1); | |
| viewPager.setCurrentItem(1); | |
| tabPosition = 1; | |
| } else if (pushtype.equalsIgnoreCase(Constants.NOTIFICATION_TYPE_FORUM)) { | |
| bottomNavigation.setCurrentItem(2); | |
| viewPager.setCurrentItem(2); | |
| tabPosition = 2; | |
| } | |
| } else { | |
| bottomNavigation.setCurrentItem(2); | |
| viewPager.setCurrentItem(2); | |
| tabPosition = 2; | |
| } | |
| } | |
| /***/ | |
| @Override | |
| public void onStart() { | |
| super.onStart(); | |
| NYBus.get().register(this, Channel.DEFAULT); | |
| SharedPreferenceManager.getSharedPrefs().registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener); | |
| } | |
| @Override | |
| public void onStop() { | |
| super.onStop(); | |
| NYBus.get().unregister(this, Channel.DEFAULT); | |
| SharedPreferenceManager.getSharedPrefs().unregisterOnSharedPreferenceChangeListener(sharedPreferenceChangeListener); | |
| } | |
| @Override | |
| protected void onDestroy() { | |
| super.onDestroy(); | |
| Log.d(TAG, "onDestroy: "); | |
| } | |
| @Override | |
| protected void onActivityResult(int requestCode, int resultCode, Intent data) { | |
| Log.e(TAG, "onActivityResult: "); | |
| if (requestCode == REQUEST_CODE) { | |
| if (resultCode == Activity.RESULT_OK) { | |
| title = data.getExtras().getString("title"); | |
| isThereResultFromPreviousActivity = true; | |
| } | |
| } | |
| if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) { | |
| CropImage.ActivityResult result = CropImage.getActivityResult(data); | |
| if (resultCode == RESULT_OK) { | |
| Log.d(TAG, "onActivityResult: CropImage" + result.getUri()); | |
| Bitmap bitmapResized = UtilsJiggle.getBitmap(result, this); | |
| listener.getImageUrl(bitmapResized, result.getUri()); | |
| } else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) { | |
| Exception error = result.getError(); | |
| } | |
| } | |
| Log.d(TAG, "onActivityResult() called with: requestCode = [" + requestCode + "], resultCode = [" + resultCode + "], data = [" + data + "]"); | |
| if (requestCode == VideoPicker.VIDEO_PICKER_REQUEST_CODE && resultCode == RESULT_OK) { | |
| List<String> mPath = new ArrayList<>(); | |
| mPath = (List<String>) data.getSerializableExtra(VideoPicker.EXTRA_VIDEO_PATH); | |
| listener.getVideoPath(mPath.get(0)); | |
| Log.d(TAG, "onActivityResult: video: " + mPath); | |
| } | |
| } | |
| @Override | |
| public void onBackPressed() { | |
| // NYBus.get().post("OnBackPressed", Channel.TWO); | |
| if (isRunning) { | |
| if (HomeFragment.SEARCH_VISIBLE) { | |
| Log.d(TAG, "HomeFragment SEARCH_VISIBLE: " + HomeFragment.SEARCH_VISIBLE); | |
| NYBus.get().post("onBackPressed", Channel.FOUR); | |
| } else if (ForumFragment.SEARCH_VISIBLE) { | |
| Log.d(TAG, "ForumFragment SEARCH_VISIBLE: " + ForumFragment.SEARCH_VISIBLE); | |
| NYBus.get().post("onBackPressed", Channel.FIVE); | |
| } else if (InboxFragment.SEARCH_VISIBLE) { | |
| Log.d(TAG, "InboxFragment SEARCH_VISIBLE: " + InboxFragment.SEARCH_VISIBLE); | |
| NYBus.get().post("onBackPressed", Channel.EIGHT); | |
| } else if (ConnectionsFragment.SEARCH_VISIBLE) { | |
| Log.d(TAG, "ConnectionsFragment SEARCH_VISIBLE: " + ConnectionsFragment.SEARCH_VISIBLE); | |
| NYBus.get().post("onBackPressed", Channel.SIX); | |
| } else if (ConnectionListFragment.SEARCH_VISIBLE) { | |
| Log.d(TAG, "ConnectionListFragment SEARCH_VISIBLE: " + ConnectionListFragment.SEARCH_VISIBLE); | |
| NYBus.get().post("onBackPressed", Channel.SEVEN); | |
| } else if (MediaFragment.SEARCH_VISIBLE) { | |
| Log.d(TAG, "MediaFragment SEARCH_VISIBLE: " + MediaFragment.SEARCH_VISIBLE); | |
| NYBus.get().post("MediaFragment", Channel.NINE); | |
| } else if (ImportContactsFragment.SEARCH_VISIBLE) { | |
| Log.d(TAG, "ImportContactsFragment SEARCH_VISIBLE: " + ImportContactsFragment.SEARCH_VISIBLE); | |
| NYBus.get().post("ImportContactsFragment", Channel.NINE); | |
| } else if (UsersConnectionFragment.SEARCH_VISIBLE) { | |
| Log.d(TAG, "UsersConnectionFragment SEARCH_VISIBLE: " + UsersConnectionFragment.SEARCH_VISIBLE); | |
| NYBus.get().post("UsersConnectionFragment", Channel.SEVEN); | |
| } | |
| else { | |
| if (mPagerAdapter.getItem(viewPager.getCurrentItem()).getChildFragmentManager().getBackStackEntryCount() > 0) { | |
| mPagerAdapter.getItem(viewPager.getCurrentItem()).getChildFragmentManager().popBackStack(); | |
| } else { | |
| exitFromActivity(); | |
| } | |
| } | |
| UtilsJiggle.hideSoftKeyboard(this); | |
| } | |
| } | |
| @Override | |
| protected void onPause() { | |
| super.onPause(); | |
| disposable.dispose(); | |
| // navigateToFragmentDisposable.dispose(); | |
| isRunning = false; | |
| } | |
| @Override | |
| protected void onResume() { | |
| super.onResume(); | |
| isRunning = true; | |
| if (isThereResultFromPreviousActivity) { | |
| openNewContentFragment(Constants.FragmentPackageName.FRAGMENT_SUB_CATEGORY, title, "0"); | |
| isThereResultFromPreviousActivity = false; | |
| } | |
| disposable = ReactiveNetwork.observeInternetConnectivity() | |
| .subscribeOn(Schedulers.io()) | |
| .observeOn(AndroidSchedulers.mainThread()) | |
| .subscribe(new Consumer<Boolean>() { | |
| @Override | |
| public void accept(Boolean isConnectedToInternet) { | |
| // do something with isConnectedToInternet value | |
| Log.d(TAG, "accept: " + isConnectedToInternet); | |
| if (isConnectedToInternet && !dataLoaded) { | |
| initPresenter(); | |
| } | |
| } | |
| }); | |
| } | |
| public void openNewContentFragment(String fragmentPackageName, String gson, String id) { | |
| ContainerFragment hostFragment = (ContainerFragment) mPagerAdapter.getItem(viewPager.getCurrentItem()); | |
| try { | |
| Fragment newFragment = ((Fragment) (Class.forName(fragmentPackageName).newInstance())); | |
| Bundle args = new Bundle(); | |
| args.putString("id", id); | |
| args.putString(Constants.IntentArgsKey.INTENT_GSON_DATA, gson); | |
| newFragment.setArguments(args); | |
| hostFragment.replaceFragment(newFragment, true); | |
| } catch (InstantiationException e) { | |
| e.printStackTrace(); | |
| } catch (IllegalAccessException e) { | |
| e.printStackTrace(); | |
| } catch (ClassNotFoundException e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| private void initPresenter() { | |
| presenter = new NavigationPresenter(this); | |
| presenter.getUserProfile(SharedPreferenceManager.getInstance().getString(Constants.SharedPreferenceKey.SHAREDPREF_USER_ID)); | |
| } | |
| public void exitFromActivity() { | |
| int bottomNavigationIndex = bottomNavigationStack.pop(); // return stack top item | |
| if (bottomNavigationIndex != -1) { | |
| viewPager.setCurrentItem(bottomNavigationIndex); | |
| tabPosition = bottomNavigationIndex; | |
| bottomNavigation.setCurrentItem(bottomNavigationIndex); | |
| } else { | |
| if (tabPosition == 2) {//if forum tab selected exit from activity | |
| if (doubleBackToExitPressedOnce) { | |
| if (getSupportFragmentManager().getBackStackEntryCount() > 0) { | |
| getSupportFragmentManager().popBackStackImmediate(); | |
| } | |
| super.onBackPressed(); | |
| return; | |
| } | |
| this.doubleBackToExitPressedOnce = true; | |
| Toast.makeText(this, "Please click BACK again to exit", Toast.LENGTH_SHORT).show(); | |
| new Handler().postDelayed(new Runnable() { | |
| @Override | |
| public void run() { | |
| doubleBackToExitPressedOnce = false; | |
| } | |
| }, 2000); | |
| } else {//select forum tab if not selected | |
| viewPager.setCurrentItem(2); | |
| tabPosition = 2; | |
| bottomNavigation.setCurrentItem(2); | |
| bottomNavigationStack.clearItem(); | |
| } | |
| } | |
| } | |
| @Override | |
| public void showSearchActivity() { | |
| Intent intent = new Intent(this, SearchActivity.class); | |
| startActivity(intent); | |
| UtilsJiggle.showForwardTransition(this); | |
| } | |
| @Override | |
| public void switchAccount() { | |
| } | |
| @Override | |
| public void noInternet(String s) { | |
| UtilsJiggle.showLongToast(this, s); | |
| } | |
| @Override | |
| public void onError(String errorText) { | |
| if (errorText.equalsIgnoreCase("Token Expired")) { | |
| Log.d(TAG, "mobile number: " + SharedPreferenceManager.getInstance().getString(Constants.SharedPreferenceKey.USER_PHONE_NUMBER)); | |
| } else { | |
| UtilsJiggle.showShortToast(this, errorText); | |
| } | |
| } | |
| @Override | |
| public void onSuccess(UserProfileModel userProfileModel) { | |
| dataLoaded = true; | |
| Log.d(TAG, "onSuccess: " + userProfileModel.toString()); | |
| SharedPreferenceManager.getInstance().setString(Constants.SharedPreferenceKey.USER_PHONE_NUMBER, | |
| userProfileModel.getUsername()); | |
| SharedPreferenceManager.getInstance().setString(Constants.SharedPreferenceKey.USER_PROFILE, | |
| new Gson().toJson(userProfileModel.getUserProfile())); | |
| SharedPreferenceManager.getInstance().setString(Constants.SharedPreferenceKey.USER_NAME, | |
| userProfileModel.getUserProfile().getFirstName() + " " + userProfileModel.getUserProfile().getLastName()); | |
| if (userProfileModel.getUserProfile().getImage() != null) { | |
| SharedPreferenceManager.getInstance().setString(Constants.SharedPreferenceKey.USER_IMAGE_URL, | |
| userProfileModel.getUserProfile().getImage().getUrl()); | |
| NYBus.get().post(userProfileModel.getUserProfile().getImage().getUrl(), Channel.ONE); | |
| } | |
| } | |
| @Override | |
| public void onTokenSuccess(LoginRP loginRP) { | |
| Log.d(TAG, "onTokenSuccess: "); | |
| SharedPreferenceManager.getInstance().setBoolean(Constants.TOKEN_UPDATED, true); | |
| SharedPreferenceManager.getInstance().setString(Constants.SharedPreferenceKey.SHAREDPREF_AUTHENTICATION_TOKEN, loginRP.getId()); | |
| SharedPreferenceManager.getInstance().setString(Constants.SharedPreferenceKey.SHAREDPREF_USER_ID, loginRP.getUserId()); | |
| presenter.getUserProfile(SharedPreferenceManager.getInstance().getString(Constants.SharedPreferenceKey.SHAREDPREF_USER_ID)); | |
| } | |
| public void openMyProfile() { | |
| Intent intent = new Intent(this, UserProfileActivity.class); | |
| startActivity(intent); | |
| UtilsJiggle.showForwardTransition(this); | |
| } | |
| public void setListener(OnImageUrlLoadedListener listener) { | |
| this.listener = listener; | |
| } | |
| public void updateBadgeCount() { | |
| Log.d(TAG, "updateBadgeCount: "); | |
| } | |
| @Override | |
| public void onConnect(Object... args) { | |
| Log.d(TAG, "onConnect: "); | |
| } | |
| @Override | |
| public void onDisconnect(Object... args) { | |
| Log.d(TAG, "onDisconnect: "); | |
| } | |
| @Override | |
| public void onConnectError(Object... args) { | |
| } | |
| @Override | |
| public void onError(Object... args) { | |
| Log.d(TAG, "onError: "); | |
| } | |
| @Override | |
| public void onConnectTimeout(Object... args) { | |
| } | |
| /***/ | |
| @Override | |
| public void onNewMessage(Object... args) { | |
| Log.d(TAG, "onNewMessage: SharedPref "); | |
| JSONObject data = (JSONObject) args[0]; | |
| Log.d(TAG, "run: " + data); | |
| String fromId; | |
| String time; | |
| try { | |
| Log.d(TAG, "run: " + data.getString("content")); | |
| fromId = data.getString("from"); | |
| time = data.getString("created"); | |
| if (!time.equals(lasttime)) { | |
| if (mFromIds.get(fromId) == null) { | |
| mFromIds.put(fromId, 1); | |
| } else { | |
| mFromIds.put(fromId, mFromIds.get(fromId) + 1); | |
| } | |
| // SharedPreferenceManager.getInstance().setString(Constants.SharedPreferenceKey.NOTIFICATION_BADGE_COUNT, ++count + ""); | |
| lasttime = time; | |
| } | |
| Log.d(TAG, "onNewMessage: " + mFromIds.get(fromId)); | |
| } catch (JSONException e) { | |
| Log.e(TAG, e.getMessage()); | |
| return; | |
| } | |
| SharedPreferenceManager.getInstance().setString(Constants.SharedPreferenceKey.USER_ID_MSG_COUNT, new Gson().toJson(mFromIds)); | |
| // NYBus.get().post(Constants.UPDATE_MESSAGE_COUNT, Channel.SIX); | |
| } | |
| @Override | |
| public void onRegisterSuccess(Object[] args) { | |
| } | |
| @Override | |
| public void onMessageStatusUpdate(Object[] args) { | |
| Log.d(TAG, "onMessageStatusUpdate: "); | |
| } | |
| @Override | |
| public void onReconnectAttempt(Object[] args) { | |
| Log.d(TAG, "onReconnectAttempt: "); | |
| } | |
| @Override | |
| public void onReconnect(Object[] args) { | |
| Log.d(TAG, "onReconnect: "); | |
| } | |
| @Subscribe(channelId = Channel.DEFAULT) | |
| public void onEvent(String msg) { | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment