Android Open Source - Lessaging Conversations List






From Project

Back to project page Lessaging.

License

The source code is released under:

GNU General Public License

If you think the Android project Lessaging listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package fr.lessaging.conversation;
//  ww w. j  a v a  2  s.c  o  m
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;
import android.util.Log;

import java.util.ArrayList;

import fr.lessaging.utils.AppConfig;

/**
 * Created by lheido on 05/12/14.
 */
public class ConversationsList {

    private static ArrayList<Conversation> list;
    private static boolean isFirstLoaded;
    private static int i;
    private static ConversationsListActionsListener actionsListener;

    public static void load(final Context context, final ConversationsListLoadingListener callback){
        if (listIsNull()) {
            list = new ArrayList<>();
        }
        if (listIsEmpty()){
            //populate list
            isFirstLoaded = false;
            i = 0;
            new AsyncTask<Void, Conversation, Boolean>() {
                @Override
                protected Boolean doInBackground(Void... voids) {
                    final String[] projection = new String[] {"_id", "date", "message_count", "recipient_ids", "read", "type"};
                    Uri uri = Uri.parse("content://mms-sms/conversations?simple=true");
                    Cursor query = context.getContentResolver().query(uri, projection, null, null, "date DESC");
                    if(query != null) {
                        if (query.moveToFirst()) {
                            do {
                                Conversation conversation = Conversation.getConversationInfo(context, query);
                                publishProgress(conversation);
                            } while (query.moveToNext());
                        }
                        query.close();
                    }
                    return true;
                }

                @Override
                protected void onProgressUpdate (Conversation... prog){
                    Conversation conversation = prog[0];
                    list.add(conversation);
                    if(callback != null){
                        callback.onConversationLoaded(conversation, i);
                        if(!isFirstLoaded){
                            isFirstLoaded = true;
                            callback.onFirstConversationLoaded(conversation, i);
                        }
                    }
                    i++;
                }

            }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        } else {
            callback.isAlreadyLoaded();
        }
    }

    public static Conversation get(int index){
        if(!listIsNull() && !listIsEmpty()) {
            return list.get(index);
        }
        return null;
    }

    public static void add(Conversation conversation){
        add(list.size(), conversation);
    }

    public static void add(int index, Conversation conversation){
        if(!listIsNull() && !listIsEmpty()) {
            list.add(index, conversation);
            if(actionsListener != null){
                actionsListener.onItemAdded();
            }
        }
    }

    public static int size(){
        if(!listIsNull() && !listIsEmpty()){
            return list.size();
        }
        return -1;
    }

    public static void moveIndexToTop(int index){
        if(!listIsNull() && !listIsEmpty()){
            Conversation c = list.remove(index);
            list.add(0, c);
            list.get(0).nbSmsIncrese();
            if(actionsListener != null){
                actionsListener.onItemMovedToTop();
            }
        }
    }

    public static void moveConversationToTop(Conversation conversation){
        if(!listIsNull() && !listIsEmpty()) {
            int index = list.indexOf(conversation);
            moveIndexToTop(index);
        }
    }

    private static boolean listIsNull(){
        boolean result = true;
        if (list != null) {
            result = false;
        } else if (AppConfig.DEBUG) {
            Log.v("ConversationsList", "list = null");
        }
        return result;
    }

    private static boolean listIsEmpty(){
        boolean result = true;
        if (!list.isEmpty()) {
            result = false;
        } else if (AppConfig.DEBUG) {
            Log.v("ConversationsList", "list is empty");
        }
        return result;
    }

    public static void setActionsListener(ConversationsListActionsListener actionsListener) {
        if(ConversationsList.actionsListener != null && actionsListener != null){
            if(AppConfig.DEBUG){
                Log.w("setActionsListener", "Multiple calls to setActionsListener method.");
            }
        }
        ConversationsList.actionsListener = actionsListener;
    }

    /**
     * Callback interface for loading conversations list.
     */
    public interface ConversationsListLoadingListener {
        public void onConversationLoaded(Conversation conversation, int index);
        public void onFirstConversationLoaded(Conversation conversation, int index);
//        public void onConversationsListLoaded();
        public void isAlreadyLoaded();
    }

    /**
     * Callback interface for add/move action.
     * Must be set to null when activity/fragment call onPause or onDestroy methods.
     */
    public interface ConversationsListActionsListener {
        public void onItemAdded();
        public void onItemMovedToTop();
    }

}




Java Source Code List

fr.lessaging.ApplicationTest.java
fr.lessaging.MainActivity.java
fr.lessaging.adapters.ConversationsListAdapter.java
fr.lessaging.adapters.MmsAdapter.java
fr.lessaging.adapters.SmsAdapter.java
fr.lessaging.adapters.SmsBaseAdapter.java
fr.lessaging.adapters.ViewPagerAdapter.java
fr.lessaging.conversation.Conversation.java
fr.lessaging.conversation.ConversationsList.java
fr.lessaging.fragments.CurrentConversationFragment.java
fr.lessaging.fragments.MmsFragment.java
fr.lessaging.fragments.NavigationDrawerFragment.java
fr.lessaging.fragments.SmsBaseFragment.java
fr.lessaging.fragments.SmsFragment.java
fr.lessaging.message.MessageManager.java
fr.lessaging.message.MessageTaskCallback.java
fr.lessaging.message.Message.java
fr.lessaging.message.MmsTask.java
fr.lessaging.message.SmsTask.java
fr.lessaging.preferences.LessagingPreference.java
fr.lessaging.preferences.PrefConversationFragment.java
fr.lessaging.preferences.PrefGeneralFragment.java
fr.lessaging.preferences.PrefListConversationsFragment.java
fr.lessaging.preferences.PrefReceiveFragment.java
fr.lessaging.receiver.MessageReceiver.java
fr.lessaging.utils.AppConfig.java
fr.lessaging.utils.BuildFragment.java
fr.lessaging.utils.LessagingNotification.java
fr.lessaging.utils.LessagingVibrator.java
fr.lessaging.utils.UserPref.java