Skip to content

Commit

Permalink
Merge branch 'release/alpha-0.2.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
kb10uy committed Jul 8, 2015
2 parents ccfab34 + d3eb647 commit 09a1877
Show file tree
Hide file tree
Showing 22 changed files with 496 additions and 147 deletions.
1 change: 1 addition & 0 deletions .idea/dictionaries/kb10uy.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ android {
applicationId "org.kb10uy.tencocoa"
minSdkVersion 17
targetSdkVersion 21
versionCode 11
versionName "0.2.1 (build 11, Kbtter7.0.2.1, Dragonforce)"
versionCode 14
versionName "0.2.4 (build 14, Kbtter7.0.2.4, Dragonforce)"
}
buildTypes {
release {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Expand Down
23 changes: 20 additions & 3 deletions app/src/main/java/org/kb10uy/tencocoa/AccountsListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ public class AccountsListActivity extends AppCompatActivity {
ArrayList<TwitterAccountInformation> accounts;
GeneralListAdapter<TwitterAccountInformation> accountsAdapter;
Intent resultIntent = new Intent();
SharedPreferences pref;

@Override
protected void onCreate(Bundle savedInstanceState) {
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
pref = PreferenceManager.getDefaultSharedPreferences(this);
TencocoaHelper.setCurrentTheme(this, pref.getString(getString(R.string.preference_appearance_theme), "Black"));
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_accounts_list);
Expand Down Expand Up @@ -96,20 +97,27 @@ protected void onSaveInstanceState(Bundle outState) {
protected void onNewIntent(Intent intent) {
if (intent == null || intent.getData() == null || !intent.getData().toString().startsWith(mCallback))
return;
Uri data = intent.getData();
String verifier = intent.getData().getQueryParameter("oauth_verifier");
final Activity ta = this;

AsyncTask<String, Void, AccessToken> task = new AsyncTask<String, Void, AccessToken>() {
@Override
protected AccessToken doInBackground(String... params) {
try {
if (mRequestToken == null) {
String rt = pref.getString(getString(R.string.preference_twitter_request_token), "");
String rts = pref.getString(getString(R.string.preference_twitter_request_token_secret), "");
mRequestToken = new RequestToken(rt, rts);
}
return mTwitter.getOAuthAccessToken(mRequestToken, params[0]);
} catch (TwitterException e) {
e.printStackTrace();
return null;
} catch (IllegalStateException e) {
e.printStackTrace();
return null;
}
return null;
}

@Override
Expand All @@ -120,6 +128,10 @@ protected void onPostExecute(AccessToken accessToken) {
} else {
Toast.makeText(ta, R.string.text_activity_accounts_list_failed, Toast.LENGTH_SHORT).show();
}
pref.edit()
.putString(getString(R.string.preference_twitter_request_token), mRequestToken.getToken())
.putString(getString(R.string.preference_twitter_request_token_secret), mRequestToken.getTokenSecret())
.apply();
}
};
task.execute(verifier);
Expand All @@ -144,7 +156,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
newOAuthAuthorize();
return true;
case android.R.id.home:
setResult(RESULT_CANCELED, resultIntent);
setResult(RESULT_CANCELED);
finish();
return true;
}
Expand All @@ -165,6 +177,10 @@ private void newOAuthAuthorize() {
protected String doInBackground(Void... params) {
try {
mRequestToken = mTwitter.getOAuthRequestToken(mCallback);
pref.edit()
.putString(getString(R.string.preference_twitter_request_token), mRequestToken.getToken())
.putString(getString(R.string.preference_twitter_request_token_secret), mRequestToken.getTokenSecret())
.apply();
return mRequestToken.getAuthorizationURL();
} catch (TwitterException e) {
e.printStackTrace();
Expand All @@ -176,6 +192,7 @@ protected String doInBackground(Void... params) {
protected void onPostExecute(String url) {
if (url != null) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
}
}
Expand Down
12 changes: 10 additions & 2 deletions app/src/main/java/org/kb10uy/tencocoa/HomeTimeLineFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ public void onDetach() {
private View generateStatusView(View targetView, TencocoaStatus status) {
Status sourceStatus = status.getShowingStatus();
User user = sourceStatus.getUser();
View itemLayout = targetView.findViewById(R.id.StatusItemLayout);
View privateMark = targetView.findViewById(R.id.StatusItemUserPrivateMark);

((TextView) targetView.findViewById(R.id.StatusItemUserName)).setText(user.getName());
((TextView) targetView.findViewById(R.id.StatusItemUserScreenName)).setText(user.getScreenName());
Expand All @@ -130,7 +132,7 @@ private View generateStatusView(View targetView, TencocoaStatus status) {
targetView.findViewById(R.id.StatusItemFavorited).setVisibility(View.GONE);
}
if (status.isRetweet()) {
(targetView.findViewById(R.id.StatusItemLayout)).setBackgroundResource(mRewteetBackgroundValue.resourceId);
itemLayout.setBackgroundResource(mRewteetBackgroundValue.resourceId);
(targetView.findViewById(R.id.StatusItemFavRtCounts)).setVisibility(View.VISIBLE);
((TextView) targetView.findViewById(R.id.StatusItemFavoriteCount)).setText(TencocoaHelper.getCompressedNumberString(sourceStatus.getFavoriteCount()));
((TextView) targetView.findViewById(R.id.StatusItemRetweetCount)).setText(TencocoaHelper.getCompressedNumberString(sourceStatus.getRetweetCount()));
Expand All @@ -140,10 +142,16 @@ private View generateStatusView(View targetView, TencocoaStatus status) {
Glide.with(getActivity()).load(retweeter.getMiniProfileImageURLHttps()).into(((ImageView) targetView.findViewById(R.id.StatusItemRetweetedUserProfile)));
((TextView) targetView.findViewById(R.id.StatusItemRetweetedUserName)).setText(retweeter.getName());
} else {
(targetView.findViewById(R.id.StatusItemLayout)).setBackgroundResource(R.color.tencocoa_color_transparent);
itemLayout.setBackgroundResource(R.color.tencocoa_color_transparent);
(targetView.findViewById(R.id.StatusItemFavRtCounts)).setVisibility(View.GONE);
(targetView.findViewById(R.id.StatusItemRetweeterFrame)).setVisibility(View.GONE);
}

if(user.isProtected()) {
privateMark.setVisibility(View.VISIBLE);
} else {
privateMark.setVisibility(View.GONE);
}
return targetView;
}

Expand Down
36 changes: 36 additions & 0 deletions app/src/main/java/org/kb10uy/tencocoa/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.os.IBinder;
import android.preference.PreferenceManager;
Expand All @@ -22,6 +24,7 @@
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;

Expand All @@ -40,6 +43,7 @@
import java.util.concurrent.CountDownLatch;

import io.realm.Realm;
import twitter4j.StatusUpdate;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.User;
Expand All @@ -56,6 +60,8 @@ public class MainActivity
private User currentUser;
private boolean initialized = false;
private SharedPreferences pref;
private ConnectivityManager mConnectivityManager;
private NetworkInfo mCurrentNetworkInfo;

private DrawerLayout mDrawerLayout;
private FrameLayout mFrameLayout;
Expand Down Expand Up @@ -113,6 +119,8 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
protected void onStart() {
super.onStart();
mConnectivityManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);

bindTencocoaServices();
initializeTwitter();
}
Expand All @@ -136,6 +144,7 @@ protected void onPostCreate(Bundle savedInstanceState) {
protected void onResume() {
super.onResume();
checkTwitterUserExists();
mCurrentNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
//bindTencocoaServices();
}

Expand Down Expand Up @@ -171,6 +180,7 @@ protected void onDestroy() {
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_CANCELED) return;
final TwitterAccountInformation info = (TwitterAccountInformation) data.getSerializableExtra("Information");
bindTencocoaServices();
switch (requestCode) {
Expand Down Expand Up @@ -320,6 +330,10 @@ private void checkTwitterUserExists() {
}

private void startUserStream(TwitterAccountInformation info) {
if (mCurrentNetworkInfo == null || !(mCurrentNetworkInfo.isConnected())) {
showToast(getString(R.string.notification_network_unavailable));
return;
}
AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
Expand Down Expand Up @@ -502,6 +516,11 @@ public void applyUpdateStatus(String status) {
mWritePermissionService.updateStatus(status);
}

@Override
public void applyUpdateStatus(StatusUpdate status) {
mWritePermissionService.updateStatus(status);
}

@Override
public void showStatusDetail(TencocoaStatus status) {
StatusDetailDialogFragment dialog = StatusDetailDialogFragment.newInstance(status);
Expand Down Expand Up @@ -544,6 +563,15 @@ protected Realm doInBackground(Void... params) {
statusCache.setIsRetweeted(true);
statusCache.setIsFavorited(true);
break;
case StatusDetailDialogFragment.ACTION_REPLY:
NewStatusDialogFragment dialog = NewStatusDialogFragment.newInstance(status);
dialog.show(getFragmentManager(), "NewStatus");
break;
case StatusDetailDialogFragment.ACTION_REPLY_BLANK:
StatusUpdate update = new StatusUpdate(TencocoaHelper.createReplyTemplate(status));
update.setInReplyToStatusId(status.getShowingStatus().getId());
mWritePermissionService.updateStatus(update);
break;
}
realm.commitTransaction();
return realm;
Expand All @@ -557,4 +585,12 @@ protected void onPostExecute(Realm realm) {
};
task.execute();
}

private void showBehaviorNotification(String title, String description) {

}

private void showToast(String text) {
Toast.makeText(ctx, text, Toast.LENGTH_SHORT);
}
}
45 changes: 42 additions & 3 deletions app/src/main/java/org/kb10uy/tencocoa/NewStatusDialogFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,34 @@
import android.app.Dialog;
import android.app.DialogFragment;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import org.kb10uy.tencocoa.model.TencocoaHelper;
import org.kb10uy.tencocoa.model.TencocoaStatus;

import twitter4j.Status;
import twitter4j.StatusUpdate;


public class NewStatusDialogFragment extends DialogFragment {

private NewStatusDialogFragmentInteractionListener mListener;
private Status replyToStatus;

public static NewStatusDialogFragment newInstance() {
return new NewStatusDialogFragment();
}

public static NewStatusDialogFragment newInstance(TencocoaStatus reply) {
NewStatusDialogFragment dialog = new NewStatusDialogFragment();
Bundle bundle = new Bundle();
bundle.putSerializable("ReplyTo", reply.getShowingStatus());
dialog.setArguments(bundle);
return dialog;
}

public NewStatusDialogFragment() {
// Required empty public constructor
}
Expand All @@ -26,19 +43,39 @@ public void onCreate(Bundle savedInstanceState) {

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Dialog dialog=new Dialog(getActivity());
final Dialog dialog = new Dialog(getActivity());
dialog.getWindow().requestFeature(STYLE_NO_TITLE);
dialog.setContentView(R.layout.fragment_new_status_dialog);
EditText teStatus = (EditText) dialog.findViewById(R.id.NewStatusDialogFragmentStatusText);
dialog.findViewById(R.id.NewStatusDialogFragmentButtonUpdateStatus).setOnClickListener(v -> {
String text = ((EditText) dialog.findViewById(R.id.NewStatusDialogFragmentEditTextStatusText)).getText().toString();
String text = teStatus.getText().toString();
dismiss();
updateStatus(text);
});

Bundle arguments = getArguments();
if (arguments == null) return dialog;
Status reply = (Status) arguments.getSerializable("ReplyTo");
if (reply != null) {
replyToStatus = reply;
String template = TencocoaHelper.createReplyTemplate(new TencocoaStatus(reply));
teStatus.setText(template);
teStatus.setSelection(template.length());
((TextView) dialog.findViewById(R.id.NewStatusDialogFragmentTitle)).setText(getString(R.string.label_dialog_new_status_reply));
((TextView) dialog.findViewById(R.id.NewStatusDialogFragmentReplyUserName)).setText(reply.getUser().getName());
((TextView) dialog.findViewById(R.id.NewStatusDialogFragmentReplyText)).setText(reply.getText());
dialog.findViewById(R.id.NewStatusDialogFragmentReply).setVisibility(View.VISIBLE);
}
return dialog;
}

public void updateStatus(String text) {
if (mListener != null) {
if (mListener == null) return;
if (replyToStatus != null) {
StatusUpdate update = new StatusUpdate(text);
update.inReplyToStatusId(replyToStatus.getId());
mListener.applyUpdateStatus(update);
} else {
mListener.applyUpdateStatus(text);
}
}
Expand All @@ -62,6 +99,8 @@ public void onDetach() {

public interface NewStatusDialogFragmentInteractionListener {
void applyUpdateStatus(String status);

void applyUpdateStatus(StatusUpdate status);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private void setStatusInfo(Dialog view) {
((TextView) view.findViewById(R.id.StatusDetailTextViewScreenName)).setText(user.getScreenName());
((TextView) view.findViewById(R.id.StatusDetailTextViewStatusText)).setText(mTargetStatus.getReplacedText());
((TextView) view.findViewById(R.id.StatusDetailTextViewCreatedAt)).setText(TencocoaHelper.getAbsoluteTimeString(mTargetStatus.getShowingStatus().getCreatedAt()));
Glide.with(getActivity()).load(user.getOriginalProfileImageURLHttps()).into(((ImageView) view.findViewById(R.id.StatusDetailImageViewUserProfile)));
Glide.with(getActivity()).load(user.getBiggerProfileImageURLHttps()).into(((ImageView) view.findViewById(R.id.StatusDetailImageViewUserProfile)));

ToggleButton tbFav = (ToggleButton) view.findViewById(R.id.StatusDetailButtonFav);
tbFav.setChecked(mTargetStatus.isFavorited());
Expand All @@ -72,10 +72,22 @@ private void setStatusInfo(Dialog view) {
mListener.onStatusDetailAction(ACTION_RETWEET, mTargetStatus);
dismiss();
});
view.findViewById(R.id.StatusDetailButtonReply).setOnClickListener(v -> {
mListener.onStatusDetailAction(ACTION_REPLY, mTargetStatus);
dismiss();
});
view.findViewById(R.id.StatusDetailButtonReplyBlank).setOnClickListener(v -> {
mListener.onStatusDetailAction(ACTION_REPLY_BLANK, mTargetStatus);
dismiss();
});
view.findViewById(R.id.StatusDetailButtonOthers).setOnClickListener(v -> {
dismiss();
//favorite();
});

if (user.isProtected()) {
view.findViewById(R.id.StatusDetailButtonRetweet).setEnabled(false);
view.findViewById(R.id.StatusDetailButtonFavRetweet).setEnabled(false);
}
}

private void fetchStatusState() {
Expand Down Expand Up @@ -117,6 +129,8 @@ public void onDetach() {
public static final int ACTION_FAVORITE_AND_RETWEET = 3;
public static final int ACTION_RETWEET = 4;
public static final int ACTION_UNRETWEET = 5;
public static final int ACTION_REPLY = 6;
public static final int ACTION_REPLY_BLANK = 7;

public interface StatusDetailInteractionListener {
void onStatusDetailAction(int type, TencocoaStatus status);
Expand Down
Loading

0 comments on commit 09a1877

Please sign in to comment.