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

CreateTopicActivity.java (2334B)


      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.util.ServerAsyncTask;
     17 import de.mtbnews.android.util.Utils;
     18 
     19 /**
     20  * Erzeugen eines neuen Themas.
     21  * 
     22  * @author Jan Dankert
     23  * 
     24  */
     25 public class CreateTopicActivity extends Activity
     26 {
     27 	private String forumId;
     28 	private SharedPreferences prefs;
     29 
     30 	@Override
     31 	protected void onCreate(Bundle savedInstanceState)
     32 	{
     33 		super.onCreate(savedInstanceState);
     34 
     35 		setTheme(((IBCApplication) getApplication()).themeResId);
     36 		setContentView(R.layout.post);
     37 
     38 		prefs = PreferenceManager.getDefaultSharedPreferences(this);
     39 		forumId = getIntent().getStringExtra("forum_id");
     40 
     41 		final TextView recipient = (TextView) findViewById(R.id.recipient);
     42 		recipient.setText("");
     43 		recipient.setVisibility(View.INVISIBLE);
     44 
     45 		final TextView label = (TextView) findViewById(R.id.recipient_label);
     46 		label.setVisibility(View.INVISIBLE);
     47 
     48 		final TextView subject = (TextView) findViewById(R.id.subject);
     49 		subject.setText("");
     50 
     51 		final TextView text = (TextView) findViewById(R.id.content);
     52 		text.setText("");
     53 
     54 		Button button = (Button) findViewById(R.id.send);
     55 		button.setOnClickListener(new OnClickListener()
     56 		{
     57 			@Override
     58 			public void onClick(View v)
     59 			{
     60 				new ServerAsyncTask(CreateTopicActivity.this, R.string.send)
     61 				{
     62 
     63 					@Override
     64 					protected void callServer() throws IOException, TapatalkException
     65 					{
     66 						TapatalkClient client = ((IBCApplication) getApplication()).getTapatalkClient();
     67 
     68 						// Login.
     69 						if (Utils.loginExceeded(client))
     70 							client.login(prefs.getString("username", ""), prefs.getString("password", ""));
     71 
     72 						client.createTopic(forumId, subject.getText().toString(), text.getText().toString());
     73 					}
     74 
     75 					protected void doOnSuccess()
     76 					{
     77 						Toast.makeText(CreateTopicActivity.this, R.string.sent_ok, Toast.LENGTH_LONG);
     78 						CreateTopicActivity.this.finish();
     79 					}
     80 				}.execute();
     81 			}
     82 		});
     83 
     84 	}
     85 
     86 }