Android Open Source - Reddit-Underground Start Screen






From Project

Back to project page Reddit-Underground.

License

The source code is released under:

This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a co...

If you think the Android project Reddit-Underground listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.mikedaguillo.reddit_underground;
//from w w  w.j  av a 2 s .c om
import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.ArrayList;

public class StartScreen extends ActionBarActivity {

    public static final String TAG = StartScreen.class.getSimpleName(); //Tag for error messages
    public static final String PREFS_NAME = "MyPrefsFile";

    private static final int LOGIN_REQUEST = 1;

    private boolean loggedIn;

    private final String LOGIN_TEXT = "Login To Your Reddit Account";
    private final String MANUAL_TEXT = "Manually Enter a Subreddit";
    private final String SUBREDDITS_TEXT = "Your Subscribed Subreddits";
    private final String SAVED_SUBREDDITS_TEXT = "Your Stored Subreddits";
    private final String LOGOUT_TEXT = "Logout";

    private ListView listView;

    private String[] loggedOutOptions = new String[] {LOGIN_TEXT, MANUAL_TEXT};
    private String[] loggedInOptions = new String[] {MANUAL_TEXT, SUBREDDITS_TEXT, SAVED_SUBREDDITS_TEXT, LOGOUT_TEXT};

    private ArrayAdapter<String> loggedOutAdapter;
    private ArrayAdapter<String> loggedInAdapter;

    private ArrayList<String> subscribedSubreddits;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_start_screen);

        loggedOutAdapter = new ArrayAdapter<String>(this, R.layout.menu_item, R.id.menuItem, loggedOutOptions);
        loggedInAdapter = new ArrayAdapter<String>(this, R.layout.menu_item, R.id.menuItem, loggedInOptions);

        listView = (ListView) findViewById(R.id.startScreenListView);

        if (savedInstanceState != null && savedInstanceState.getBoolean("LoggedIn")) {
            listView.setAdapter(loggedInAdapter);
        }
        else {
            listView.setAdapter(loggedOutAdapter);
        }



        // ListView Item Click Listener
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                int itemPosition = position; // ListView Clicked item index

                if (!loggedIn) {
                    switch (itemPosition) {
                        case 0:
                            Intent intent = new Intent(view.getContext(), LoginScreen.class);
                            startActivityForResult(intent, LOGIN_REQUEST);
                            break;
                        case 1:
                            intent = new Intent(view.getContext(), ManualEntryScreen.class);
                            startActivity(intent);
                            break;
                    }
                }
                else {
                    switch (itemPosition) {
                        case 0:
                            Intent intent = new Intent(view.getContext(), ManualEntryScreen.class);
                            startActivity(intent);
                            break;
                        case 1:
                            intent = new Intent(view.getContext(), SubredditsSelectionScreen.class);
                            intent.putStringArrayListExtra("Subreddits", subscribedSubreddits);
                            startActivity(intent);
                            break;
                        case 2:
                            intent = new Intent(view.getContext(), SavedSubredditsScreen.class);
                            startActivity(intent);
                            break;
                        case 3:
                            loggedIn = false;
                            listView.setAdapter(loggedOutAdapter);
                            break;
                    }
                }
            }
        });

    }

   /* @Override
    protected void onStart() {
        super.onStart();

        // Loads the projects during the onStart so they are reloaded when the activity is resumed
        // after creating a new project

        // Gets the database helper to access the database for the application
        SubredditsDatabaseHelper database = new SubredditsDatabaseHelper(this);
        // Use the helper to get the list of projects from the database
        storedSubreddits = database.getSubreddits();
        database.close();

    }*/

    @Override
    public android.support.v4.app.FragmentManager getSupportFragmentManager() {
        return null;
    }

    @Override
    protected void onResume() {
        super.onResume();
        TinyDB tinyDB = new TinyDB(this);
        loggedIn = tinyDB.getBoolean("LoggedIn");
        subscribedSubreddits = tinyDB.getList("Subreddits");

        if (loggedIn) {
            listView.setAdapter(loggedInAdapter);
        }

        Log.i(TAG, "onResume completed");
    }

    @Override
    protected void onPause() {
        super.onPause();
        TinyDB tinyDB = new TinyDB(this);
        tinyDB.putBoolean("LoggedIn", loggedIn);
        tinyDB.putList("Subreddits", subscribedSubreddits);


        Log.i(TAG, "onPause completed");
    }

    @Override
    public void onSaveInstanceState(Bundle savedInstanceState) {
        super.onSaveInstanceState(savedInstanceState);
        // Save UI state changes to the savedInstanceState.
        // This bundle will be passed to onCreate if the process is
        // killed and restarted.
        savedInstanceState.putBoolean("LoggedIn", loggedIn);
        Log.i(TAG, "onSavedInstanceState completed");
    }

    @Override
    public void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        // Restore UI state from the savedInstanceState.
        // This bundle has also been passed to onCreate.
        loggedIn = savedInstanceState.getBoolean("LoggedIn");
        Log.i(TAG, "onRestoreInstanceState completed");
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch(requestCode) {
            case (LOGIN_REQUEST) : {
                if (resultCode == Activity.RESULT_OK) {
                    String newText = data.getStringExtra("Reddit Account");

                    // Change the login state and save the state to the preferences
                    loggedIn = true;
                    subscribedSubreddits = data.getStringArrayListExtra("Subreddits");
                    TinyDB tinyDB = new TinyDB(this);
                    tinyDB.putBoolean("LoggedIn", loggedIn);
                    tinyDB.putList("Subreddits", subscribedSubreddits);
                    Log.i(TAG, newText);
                    Log.i(TAG, "You are subscribed to this many subreddits: " + subscribedSubreddits.size());
                    listView.setAdapter(loggedInAdapter);
                    Log.i(TAG, "onActivityResult completed");
                }
                break;
            }
        }
    }
}




Java Source Code List

com.cd.reddit.RedditException.java
com.cd.reddit.Reddit.java
com.cd.reddit.exception.RedditRateLimitException.java
com.cd.reddit.http.QueryBuilder.java
com.cd.reddit.http.RedditRequestor.java
com.cd.reddit.http.util.RedditApiParameterConstants.java
com.cd.reddit.http.util.RedditApiResourceConstants.java
com.cd.reddit.http.util.RedditRequestInput.java
com.cd.reddit.http.util.RedditRequestResponse.java
com.cd.reddit.json.jackson.RedditJacksonManager.java
com.cd.reddit.json.jackson.RedditJsonParser.java
com.cd.reddit.json.mapping.RedditAccount.java
com.cd.reddit.json.mapping.RedditComment.java
com.cd.reddit.json.mapping.RedditJsonMessage.java
com.cd.reddit.json.mapping.RedditLink.java
com.cd.reddit.json.mapping.RedditMessage.java
com.cd.reddit.json.mapping.RedditMore.java
com.cd.reddit.json.mapping.RedditSubreddit.java
com.cd.reddit.json.mapping.RedditType.java
com.cd.reddit.json.util.RedditComments.java
com.cd.reddit.json.util.RedditJsonConstants.java
com.mikedaguillo.reddit_underground.ApplicationTest.java
com.mikedaguillo.reddit_underground.ImageViewScreen.java
com.mikedaguillo.reddit_underground.LoginScreen.java
com.mikedaguillo.reddit_underground.ManualEntryScreen.java
com.mikedaguillo.reddit_underground.RedditInstance.java
com.mikedaguillo.reddit_underground.RedditListItem.java
com.mikedaguillo.reddit_underground.SavedSubredditsScreen.java
com.mikedaguillo.reddit_underground.StartScreen.java
com.mikedaguillo.reddit_underground.SubredditsSelectionScreen.java
com.mikedaguillo.reddit_underground.TinyDB.java
com.mikedaguillo.reddit_underground.SubredditDatabaseModel.SubredditsDatabaseHelper.java