mirror of
https://github.com/nuclearfog/Shitter.git
synced 2025-01-31 19:34:55 +01:00
Base function finished
This commit is contained in:
parent
79667fbf41
commit
dc76f332f5
@ -4,6 +4,8 @@ import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import twitter4j.StatusUpdate;
|
||||
import twitter4j.Twitter;
|
||||
|
||||
@ -13,9 +15,11 @@ public class SendStatus extends AsyncTask<Object, Void, Boolean> {
|
||||
|
||||
private Context context;
|
||||
private Twitter twitter;
|
||||
private String path = "";
|
||||
|
||||
public SendStatus(Context context) {
|
||||
public SendStatus(Context context, String path) {
|
||||
this.context = context;
|
||||
this.path = path;
|
||||
twitter = TwitterResource.getInstance(context).getTwitter();
|
||||
}
|
||||
|
||||
@ -29,12 +33,14 @@ public class SendStatus extends AsyncTask<Object, Void, Boolean> {
|
||||
try {
|
||||
String tweet = (String) args[0];
|
||||
StatusUpdate mStatus = new StatusUpdate(tweet);
|
||||
if(args.length > 1)
|
||||
if(args.length > 1) { //ANSWER TO USER
|
||||
mStatus.setInReplyToStatusId((Long)args[1]);
|
||||
|
||||
}
|
||||
if(path.isEmpty()) { //ADD IMAGE
|
||||
mStatus.setMedia(new File(path));
|
||||
}
|
||||
twitter.tweets().updateStatus(mStatus);
|
||||
return true;
|
||||
|
||||
} catch(Exception err) {
|
||||
err.printStackTrace();
|
||||
}
|
||||
|
@ -1,10 +1,17 @@
|
||||
package org.nuclearfog.twidda.window;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import org.nuclearfog.twidda.backend.SendStatus;
|
||||
@ -18,7 +25,9 @@ import org.nuclearfog.twidda.database.ColorPreferences;
|
||||
public class TweetPopup extends AppCompatActivity implements View.OnClickListener {
|
||||
|
||||
private EditText tweetfield;
|
||||
private ImageView tweetImg;
|
||||
private long inReplyId;
|
||||
private String imgPath;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle SavedInstance) {
|
||||
@ -28,13 +37,16 @@ public class TweetPopup extends AppCompatActivity implements View.OnClickListene
|
||||
|
||||
Button tweetButton = (Button) findViewById(R.id.sendTweet);
|
||||
Button closeButton = (Button) findViewById(R.id.close);
|
||||
Button imageButton = (Button) findViewById(R.id.image);
|
||||
tweetfield = (EditText) findViewById(R.id.tweet_input);
|
||||
tweetImg = (ImageView) findViewById(R.id.tweetImg);
|
||||
|
||||
final int size = LinearLayout.LayoutParams.WRAP_CONTENT;
|
||||
getWindow().setLayout(size, size);
|
||||
|
||||
closeButton.setOnClickListener(this);
|
||||
tweetButton.setOnClickListener(this);
|
||||
imageButton.setOnClickListener(this);
|
||||
|
||||
LinearLayout root = (LinearLayout) findViewById(R.id.tweet_popup);
|
||||
ColorPreferences mColor = ColorPreferences.getInstance(this);
|
||||
@ -56,8 +68,29 @@ public class TweetPopup extends AppCompatActivity implements View.OnClickListene
|
||||
case R.id.close:
|
||||
finish();
|
||||
break;
|
||||
case R.id.image:
|
||||
Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
|
||||
startActivityForResult(i, RESULT_FIRST_USER);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int reqCode, int returnCode, Intent i){
|
||||
super.onActivityResult(reqCode,returnCode,i);
|
||||
if(returnCode == RESULT_OK){
|
||||
Uri imageInput = i.getData();
|
||||
String[] filepath = {MediaStore.Images.Media.DATA};
|
||||
Cursor c = getContentResolver().query(imageInput,filepath,null,null,null);
|
||||
if(c.moveToFirst()) {
|
||||
int index = c.getColumnIndex(filepath[0]);
|
||||
imgPath = c.getString(index);
|
||||
Bitmap img = BitmapFactory.decodeFile(imgPath);
|
||||
tweetImg.setImageBitmap(img);
|
||||
tweetImg.setVisibility(View.VISIBLE);
|
||||
}
|
||||
c.close();
|
||||
}
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -68,11 +101,16 @@ public class TweetPopup extends AppCompatActivity implements View.OnClickListene
|
||||
|
||||
private void send() {
|
||||
String tweet = tweetfield.getText().toString();
|
||||
SendStatus sendTweet = new SendStatus(getApplicationContext());
|
||||
if(inReplyId > 0)
|
||||
SendStatus sendTweet;
|
||||
if(imgPath == null) {
|
||||
sendTweet = new SendStatus(getApplicationContext(), "");
|
||||
} else {
|
||||
sendTweet = new SendStatus(getApplicationContext(), imgPath);
|
||||
} if(inReplyId > 0) {
|
||||
sendTweet.execute(tweet, inReplyId);
|
||||
else
|
||||
} else {
|
||||
sendTweet.execute(tweet);
|
||||
}
|
||||
finish();
|
||||
}
|
||||
}
|
4
app/src/main/res/drawable/image.xml
Normal file
4
app/src/main/res/drawable/image.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<vector android:height="24dp" android:viewportHeight="20.0"
|
||||
android:viewportWidth="20.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FFFFFF" android:pathData="M10,8c-1.657,0 -3,1.344 -3,3s1.343,3 3,3c1.656,0 3,-1.344 3,-3S11.656,8 10,8zM18,5h-2.4c-0.33,0 -0.686,-0.256 -0.789,-0.57L14.19,2.569C14.085,2.256 13.731,2 13.4,2H6.6C6.27,2 5.914,2.256 5.811,2.568L5.189,4.43C5.085,4.744 4.73,5 4.4,5H2C0.9,5 0,5.9 0,7v9c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2V7C20,5.9 19.1,5 18,5zM10,16c-2.762,0 -5,-2.238 -5,-5s2.238,-5 5,-5c2.761,0 5,2.238 5,5S12.761,16 10,16zM17.5,8.2c-0.387,0 -0.7,-0.314 -0.7,-0.701c0,-0.385 0.313,-0.7 0.7,-0.7s0.7,0.314 0.7,0.7C18.2,7.886 17.887,8.2 17.5,8.2z"/>
|
||||
</vector>
|
@ -22,7 +22,7 @@
|
||||
<TabWidget
|
||||
android:id="@android:id/tabs"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bar_wide" />
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@android:id/tabcontent"
|
||||
|
@ -130,7 +130,7 @@
|
||||
<TabWidget
|
||||
android:id="@android:id/tabs"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bar_wide" />
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@android:id/tabcontent"
|
||||
|
@ -1,16 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/tweet_popup"
|
||||
android:layout_width="300dp"
|
||||
android:layout_height="200dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:background="@color/tweetwindow"
|
||||
android:orientation="vertical">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/tweet_input"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="150dp"
|
||||
android:layout_width="300dp"
|
||||
android:layout_height="200dp"
|
||||
android:layout_marginLeft="5dip"
|
||||
android:layout_marginRight="5dip"
|
||||
android:layout_marginTop="5dip"
|
||||
@ -19,12 +20,34 @@
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginBottom="5dip"
|
||||
android:layout_marginLeft="5dip"
|
||||
android:layout_marginRight="5dip"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/tweetImg"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="5dp"
|
||||
android:contentDescription="@string/tweet_image_enclosure"
|
||||
android:visibility="invisible"
|
||||
app:srcCompat="@color/twitterBlau" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_margin="10dp"
|
||||
android:gravity="right"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/image"
|
||||
style="@style/Widget.AppCompat.Button"
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_marginRight="50dp"
|
||||
android:background="@drawable/image" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/sendTweet"
|
||||
style="@style/Widget.AppCompat.Button.Borderless"
|
||||
|
@ -76,5 +76,6 @@
|
||||
<string name="link">Webseite</string>
|
||||
<string name="location">Ort</string>
|
||||
<string name="save">Speichern</string>
|
||||
<string name="tweet_image_enclosure">Image Enclosure</string>
|
||||
|
||||
</resources>
|
Loading…
x
Reference in New Issue
Block a user