initial commit

This commit is contained in:
NudeDude 2017-11-05 14:57:43 +01:00
parent ddc2195667
commit 98af1f54aa
5 changed files with 110 additions and 81 deletions

View File

@ -10,9 +10,9 @@
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat">
android:theme="@style/AppTheme">
<activity
android:name=".LoginActivity"
android:name=".MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

View File

@ -1,12 +1,9 @@
package org.nuclearfog.twidda;
import android.app.Activity;
import android.app.Fragment;
import android.app.TabActivity;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AppCompatActivity;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
@ -18,14 +15,14 @@ import android.content.SharedPreferences;
import org.nuclearfog.twidda.engine.TwitterEngine;
public class LoginActivity extends Activity //Activity
public class MainActivity extends Activity
{
private Button linkButton, verifierButon, loginButton;
private Button linkButton, verifierButton, loginButton;
private EditText pin;
private Context con;
private SharedPreferences einstellungen;
private TabHost tabhost;
private SwipeRefreshLayout refresh;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -36,11 +33,11 @@ public class LoginActivity extends Activity //Activity
setContentView(R.layout.activity_login);
pin = (EditText) findViewById(R.id.pin);
linkButton = (Button) findViewById(R.id.linkButton);
verifierButon = (Button) findViewById(R.id.verifier);
verifierButton = (Button) findViewById(R.id.verifier);
loginButton = (Button) findViewById(R.id.loginButton);
linkButton.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View arg0){linkTwitter();}});
verifierButon.setOnClickListener(new View.OnClickListener() {
verifierButton.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View arg0){verifier();}});
loginButton.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View arg0){login();}});
@ -49,10 +46,6 @@ public class LoginActivity extends Activity //Activity
}
}
private void linkTwitter() {
RegisterAccount account = new RegisterAccount(con);
account.execute("");
@ -62,7 +55,7 @@ public class LoginActivity extends Activity //Activity
String twitterPin = pin.getText().toString();
if(!twitterPin.trim().isEmpty()) {
RegisterAccount account = new RegisterAccount(con);
account.setButton(loginButton,verifierButon);
account.setButton(loginButton,verifierButton);
account.execute(twitterPin);
} else {
Toast.makeText(con,"PIN eingeben!",Toast.LENGTH_LONG).show();
@ -91,25 +84,51 @@ public class LoginActivity extends Activity //Activity
tabhost.addTab(tab3);
tabhost.setCurrentTab(0);
tabhost.getCurrentTab();
setRefreshListener();
tabhost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
switch(tabId) {
case "timeline":
ListView timeline = (ListView) findViewById(R.id.timelinelist);
TwitterEngine homeView = new TwitterEngine(getApplicationContext(), timeline);
homeView.execute(0);
break;
case "trends":
ListView trends = (ListView) findViewById(R.id.timelinelist);
TwitterEngine trendView = new TwitterEngine(getApplicationContext(), trends);
trendView.execute(1);
break;
case "mention":
ListView mentions = (ListView) findViewById(R.id.timelinelist);
break;
}
}
});
}
private void setRefreshListener() {
refresh = (SwipeRefreshLayout) findViewById(R.id.refresh_list);
refresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
switch(tabhost.getCurrentTab()) {
case(0):
ListView timeline = (ListView) findViewById(R.id.timelinelist);
TwitterEngine homeView = new TwitterEngine(getApplicationContext(), timeline);
homeView.setRefresh(refresh);
homeView.execute(0);
break;
case(1):
ListView trends = (ListView) findViewById(R.id.trendlist);
TwitterEngine trendView = new TwitterEngine(getApplicationContext(), trends);
trendView.execute(1);
break;
case(2):
ListView mentions = (ListView) findViewById(R.id.mentionlist);
TwitterEngine mentionView = new TwitterEngine(getApplicationContext(), mentions);
mentionView.execute(2);
break;

View File

@ -2,22 +2,18 @@ package org.nuclearfog.twidda.engine;
import android.content.Context;
import android.os.AsyncTask;
import twitter4j.ResponseList;
import twitter4j.Trends;
import twitter4j.Twitter;
import twitter4j.Status;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.auth.AccessToken;
import twitter4j.conf.ConfigurationBuilder;
import android.content.SharedPreferences;
import android.support.v4.widget.SwipeRefreshLayout;
import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
import org.nuclearfog.twidda.LoginActivity;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.engine.ViewAdapter.TimelineAdapter;
import org.nuclearfog.twidda.engine.ViewAdapter.TrendsAdapter;
@ -30,15 +26,19 @@ public class TwitterEngine extends AsyncTask<Integer, Void, Void>
private static Twitter twitter;
private Context context;
private ListView timeline;
private ListView list;
private TimelineAdapter timelineAdapter;
private TrendsAdapter trendsAdapter;
private SwipeRefreshLayout refresh;
public TwitterEngine(Context context, ListView timeline) {
public TwitterEngine(Context context, ListView list) {
this.context=context;
this.timeline = timeline;
this.list = list;
if(twitter == null) init();
}
public void setRefresh(SwipeRefreshLayout refresh) {
this.refresh=refresh;
}
@Override
protected Void doInBackground(Integer... args) {
@ -46,7 +46,7 @@ public class TwitterEngine extends AsyncTask<Integer, Void, Void>
android.os.Debug.waitForDebugger();
// twitter.getRateLimitStatus();
try{
try {
switch(args[0]) {
case (0): // Home Timeline
timelineAdapter = new TimelineAdapter(context,R.layout.tweet,twitter.getHomeTimeline());
@ -68,9 +68,10 @@ public class TwitterEngine extends AsyncTask<Integer, Void, Void>
@Override
protected void onPostExecute(Void v) {
if(timelineAdapter != null)
timeline.setAdapter(timelineAdapter);
list.setAdapter(timelineAdapter);
else if(trendsAdapter != null)
timeline.setAdapter(trendsAdapter);
list.setAdapter(trendsAdapter);
refresh.setRefreshing(false);
}
/**

View File

@ -5,72 +5,81 @@
android:background="@color/twitterBlau"
android:orientation="horizontal">
<TabHost
android:id="@+id/tabHost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible">
android:layout_height="match_parent">
<LinearLayout
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/refresh_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:layout_height="match_parent">
<TabWidget
android:id="@android:id/tabs"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/timeline"
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="1dp"
android:orientation="vertical">
android:layout_height="wrap_content" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/timeline_refresh"
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/timeline"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="@+id/timelinelist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true" />
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/trends"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
<LinearLayout
android:id="@+id/trends"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/mention"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="@+id/trendlist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true" />
</LinearLayout>
<ListView
<LinearLayout
android:id="@+id/mention"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="@+id/mentionlist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>
</TabHost>
</LinearLayout>

View File

@ -1,7 +1,7 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme">
<style name="AppTheme" parent="Base.Widget.Design.TabLayout">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>