Android Open Source - SharedUrlList Delete Url Task






From Project

Back to project page SharedUrlList.

License

The source code is released under:

GNU General Public License

If you think the Android project SharedUrlList 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 de.laxu.apps.sharedurllist;
//from  w  ww.j a  va2 s .  c om
import org.json.JSONException;
import org.json.JSONObject;

import android.content.SharedPreferences;
import android.net.Uri;
import android.os.AsyncTask;
import android.preference.PreferenceManager;
import android.widget.ArrayAdapter;

public class DeleteUrlTask extends AsyncTask<Void, Void, String>{
  private MainActivity mainActivity;
  private String requesturl;
  private UrlListEntry entry;

  public DeleteUrlTask(MainActivity mainActivity, UrlListEntry entry){
    this.mainActivity = mainActivity;
    this.entry = entry;
    
    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(mainActivity);
    String serverurl = sharedPrefs.getString("pref_serverurl", "");
    String token = sharedPrefs.getString("pref_token", "");
    this.requesturl = serverurl + "?api=true&token="+Uri.encode(token)+"&delete=true&id="+Uri.encode(String.valueOf(entry.getId()));
  }

  @Override
  protected String doInBackground(Void... params) {
    String json_input="";
    try {
      json_input = Util.loadFromURL(this.mainActivity, this.requesturl);
      try {
        JSONObject json = new JSONObject(json_input);
        if(json.getString("status").equals("success")){
          return null;
        }else{
          return json.getString("errormessage");
        }
      } catch (JSONException e) {
        return "JSON error";
      }    
    } catch (LoadException e) {
      return e.getError();
    }
  }

  @Override
  protected void onPostExecute(String errormessage) {
    super.onPostExecute(errormessage);
    if(errormessage == null){
      for(int i=0;i<MainActivity.urlTabs.size();i++){
        @SuppressWarnings("unchecked")
        ArrayAdapter<UrlListEntry> arrayAdapter = ((ArrayAdapter<UrlListEntry>)MainActivity.urlTabs.get(i).getListAdapter());
        arrayAdapter.remove(entry);
        arrayAdapter.notifyDataSetChanged();
      }
      Util.createNotification(this.mainActivity, "Deleted URL", entry.getUrl(), android.R.drawable.ic_menu_delete, false);
    } else {
      Util.createNotification(this.mainActivity, "Error deleting URL", errormessage, android.R.drawable.ic_menu_delete, false);
    }
  }
}




Java Source Code List

de.laxu.apps.sharedurllist.AddUrlDialog.java
de.laxu.apps.sharedurllist.DeleteUrlTask.java
de.laxu.apps.sharedurllist.EnterPasswordFragment.java
de.laxu.apps.sharedurllist.LoadUrlListTask.java
de.laxu.apps.sharedurllist.MainActivity.java
de.laxu.apps.sharedurllist.RequestTokenTask.java
de.laxu.apps.sharedurllist.SettingsActivity.java
de.laxu.apps.sharedurllist.ShareURLFragment.java
de.laxu.apps.sharedurllist.UrlListEntry.java
de.laxu.apps.sharedurllist.Util.java
de.laxu.apps.sharedurllist.listeners.OnAddUrlMenuItemClickListener.java
de.laxu.apps.sharedurllist.listeners.OnCopyMenuItemClickListener.java
de.laxu.apps.sharedurllist.listeners.OnDeleteMenuItemClickListener.java
de.laxu.apps.sharedurllist.listeners.OnRefreshMenuItemClickListener.java
de.laxu.apps.sharedurllist.listeners.OnRequestTokenMenuItemClickListener.java
de.laxu.apps.sharedurllist.listeners.OnSettingsButtonClickListener.java
de.laxu.apps.sharedurllist.listeners.OnSettingsMenuItemClickListener.java
de.laxu.apps.sharedurllist.addUrlTask.java