Android Open Source - MatchHistory-League Summoner Update Task






From Project

Back to project page MatchHistory-League.

License

The source code is released under:

MIT License

If you think the Android project MatchHistory-League 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 com.lando.matchhistory.AsyncTask;
/*from  w  w  w. j a va 2s.c  o m*/
import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;

import com.lando.matchhistory.ApiClient.ApiClient;
import com.lando.matchhistory.MainActivity;
import com.lando.matchhistory.Models.Summoner;
import com.lando.matchhistory.R;

import java.util.Map;

import io.realm.Realm;


public class SummonerUpdateTask extends AsyncTask<Void,Void,Void>{

    private UpdateSummonerListener mListener;
    private final String mSummonerName;
    private final String mRegion;
    private final Context mContext;
    public interface UpdateSummonerListener{
        void OnProcessComplete(String name);
    }
    public void setListener(UpdateSummonerListener listener){
        mListener = listener;
    }

    public SummonerUpdateTask(Context context, String name, String region, UpdateSummonerListener mListener) {
        this.mContext = context;
        this.mSummonerName = name;
        this.mRegion = region;
        this.mListener = mListener;
    }

    @Override
    protected Void doInBackground(Void... params) {
        Realm realm = null;
        Summoner summoner = null;
        Summoner oldsummoner = null;

        try{
            realm = Realm.getInstance(mContext);
            realm.beginTransaction();
            Map<String,Summoner> summonerMap = ApiClient.getLeagueApiClient().getSummoner(mRegion, mSummonerName, mContext.getResources().getString(R.string.api_key));

            summoner = summonerMap.get(mSummonerName);
            if((oldsummoner = realm.where(Summoner.class).equalTo("id",summoner.getId()).findFirst())!=null){
                summoner.setMatches(oldsummoner.getMatches());
                oldsummoner.removeFromRealm();
            }
            summoner = realm.copyToRealm(summoner);
            Log.v(MainActivity.DEBUG_INFO, summoner.getName()+" was created");
            realm.commitTransaction();

        }catch (Exception e){
            Log.v(MainActivity.DEBUG_INFO,e.getMessage());
            realm.cancelTransaction();
        }finally {
            if(realm != null)
                realm.close();
        }
        return null;
    }

    @Override
    protected void onPostExecute(Void v) {
        super.onPostExecute(v);
        if(mListener != null){
            mListener.OnProcessComplete(mSummonerName);
        }
    }
}




Java Source Code List

com.lando.matchhistory.ApplicationTest.java
com.lando.matchhistory.MainActivity.java
com.lando.matchhistory.SummonerActivity.java
com.lando.matchhistory.Adapter.DrawerAdapter.java
com.lando.matchhistory.Adapter.MatchAdapter.java
com.lando.matchhistory.ApiClient.ApiClient.java
com.lando.matchhistory.AsyncTask.BaseTask.java
com.lando.matchhistory.AsyncTask.MatchUpdateTask.java
com.lando.matchhistory.AsyncTask.SummonerUpdateTask.java
com.lando.matchhistory.AsyncTask.VersionUpdateTask.java
com.lando.matchhistory.ContentProvider.SummonerProvider.java
com.lando.matchhistory.Fragment.MasteriesFragment.java
com.lando.matchhistory.Fragment.MatchHistoryFragment.java
com.lando.matchhistory.Fragment.ProfileFragment.java
com.lando.matchhistory.Fragment.RuneFragment.java
com.lando.matchhistory.Models.Champion.java
com.lando.matchhistory.Models.CreepsPerMinDeltas.java
com.lando.matchhistory.Models.DamageTakenPerMinDeltas.java
com.lando.matchhistory.Models.GoldPerMinDeltas.java
com.lando.matchhistory.Models.Image.java
com.lando.matchhistory.Models.Item.java
com.lando.matchhistory.Models.Mastery.java
com.lando.matchhistory.Models.Match.java
com.lando.matchhistory.Models.ParticipantIdentity.java
com.lando.matchhistory.Models.Participant.java
com.lando.matchhistory.Models.Player.java
com.lando.matchhistory.Models.ProfileIcon.java
com.lando.matchhistory.Models.Rune.java
com.lando.matchhistory.Models.Stats.java
com.lando.matchhistory.Models.SummonerSpell.java
com.lando.matchhistory.Models.Summoner.java
com.lando.matchhistory.Models.Timeline.java
com.lando.matchhistory.Models.Version.java
com.lando.matchhistory.Models.XpPerMinDeltas.java
com.lando.matchhistory.Provider.RecentSuggestionProvider.java