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:allowBackup="true"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:theme="@style/Theme.AppCompat"> android:theme="@style/AppTheme">
<activity <activity
android:name=".LoginActivity" android:name=".MainActivity"
android:screenOrientation="portrait"> android:screenOrientation="portrait">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />

View File

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

View File

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

View File

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

View File

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