android-ibc-forum

Unnamed repository; edit this file 'description' to name the repository.
git clone http://git.code.weiherhei.de/android-ibc-forum.git
Log | Files | Refs

ReplyMailActivity.java (3131B)


      1 package de.mtbnews.android;
      2 
      3 import java.io.IOException;
      4 
      5 import android.app.Activity;
      6 import android.content.SharedPreferences;
      7 import android.os.Bundle;
      8 import android.preference.PreferenceManager;
      9 import android.view.View;
     10 import android.view.View.OnClickListener;
     11 import android.widget.Button;
     12 import android.widget.TextView;
     13 import android.widget.Toast;
     14 import de.mtbnews.android.tapatalk.TapatalkClient;
     15 import de.mtbnews.android.tapatalk.TapatalkException;
     16 import de.mtbnews.android.tapatalk.wrapper.Message;
     17 import de.mtbnews.android.util.ServerAsyncTask;
     18 import de.mtbnews.android.util.Utils;
     19 
     20 public class ReplyMailActivity extends Activity
     21 {
     22 	private String boxId;
     23 	private String messageId;
     24 	private TapatalkClient client;
     25 	private SharedPreferences prefs;
     26 
     27 	@Override
     28 	protected void onCreate(Bundle savedInstanceState)
     29 	{
     30 		super.onCreate(savedInstanceState);
     31 
     32 		client = ((IBCApplication) getApplication()).getTapatalkClient();
     33 
     34 		setTheme(((IBCApplication) getApplication()).themeResId);
     35 		setContentView(R.layout.post);
     36 		prefs = PreferenceManager.getDefaultSharedPreferences(this);
     37 		final TextView recipient = (TextView) findViewById(R.id.recipient);
     38 		final TextView subject = (TextView) findViewById(R.id.subject);
     39 		final TextView text = (TextView) findViewById(R.id.content);
     40 
     41 		if (getIntent().hasExtra("box_id"))
     42 		{
     43 
     44 			setTitle(R.string.reply);
     45 			boxId = getIntent().getStringExtra("box_id");
     46 			messageId = getIntent().getStringExtra("message_id");
     47 
     48 			new ServerAsyncTask(this, R.string.waitingfor_mailbox)
     49 			{
     50 				private Message message;
     51 
     52 				@Override
     53 				protected void callServer() throws TapatalkException
     54 				{
     55 					if (Utils.loginExceeded(client))
     56 						client.login(prefs.getString("username", ""), prefs.getString("password", ""));
     57 					message = client.getMessage(boxId, messageId);
     58 				}
     59 
     60 				protected void doOnSuccess()
     61 				{
     62 					// MessageActivity.this.setTitle(feed.getTitle());
     63 
     64 					recipient.setText(message.from);
     65 
     66 					// TextView name = (TextView) findViewById(R.id.item_title);
     67 					// name.setText(item.getTitle());
     68 
     69 					subject.setText(message.subject.startsWith("Re: ") ? "" : "Re: " + message.subject);
     70 
     71 					text.setText("[quote]" + message.getContent() + "[/quote]\n\n");
     72 
     73 				}
     74 			}.execute();
     75 		}
     76 		else
     77 		{
     78 			setTitle(R.string.new_message);
     79 		}
     80 
     81 		final Button button = (Button) findViewById(R.id.send);
     82 		button.setOnClickListener(new OnClickListener()
     83 		{
     84 			@Override
     85 			public void onClick(View v)
     86 			{
     87 				new ServerAsyncTask(ReplyMailActivity.this, R.string.waitingfor_sending)
     88 				{
     89 					@Override
     90 					protected void callServer() throws IOException, TapatalkException
     91 					{
     92 						if (Utils.loginExceeded(client))
     93 							client.login(prefs.getString("username", ""), prefs.getString("password", ""));
     94 
     95 						client.createMessage(new String[] { recipient.getText().toString() }, subject.getText()
     96 								.toString(), text.getText().toString());
     97 					}
     98 
     99 					protected void doOnSuccess()
    100 					{
    101 						Toast.makeText(ReplyMailActivity.this, R.string.sent_ok, Toast.LENGTH_LONG);
    102 						ReplyMailActivity.this.finish();
    103 					}
    104 				}.execute();
    105 			}
    106 		});
    107 
    108 	}
    109 }