From 90ee611af8ba4c38e70f27eb0df55e9134ad625c Mon Sep 17 00:00:00 2001 From: Renard Date: Mon, 11 Apr 2016 17:50:06 -0300 Subject: New ViewActivity, ThemeManager --- .../baiparser/MainActivity.java | 48 +++++++--------------- 1 file changed, 14 insertions(+), 34 deletions(-) (limited to 'app/src/main/java/org/bienvenidoainternet/baiparser/MainActivity.java') diff --git a/app/src/main/java/org/bienvenidoainternet/baiparser/MainActivity.java b/app/src/main/java/org/bienvenidoainternet/baiparser/MainActivity.java index 9130160..18d2e08 100644 --- a/app/src/main/java/org/bienvenidoainternet/baiparser/MainActivity.java +++ b/app/src/main/java/org/bienvenidoainternet/baiparser/MainActivity.java @@ -31,6 +31,7 @@ import com.koushikdutta.ion.Ion; import org.bienvenidoainternet.baiparser.structure.Board; import org.bienvenidoainternet.baiparser.structure.BoardItem; +import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -78,46 +79,25 @@ public class MainActivity extends AppCompatActivity @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + ThemeManager tm = new ThemeManager(this); + this.setTheme(tm.getThemeForMainActivity()); if (savedInstanceState != null) { currentThemeId = savedInstanceState.getInt("currentThemeId"); boardList = savedInstanceState.getParcelableArrayList("boardList"); } SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); - themeId = Integer.valueOf(settings.getString("pref_theme", "1")); - if (settings.getString("pref_password", "").isEmpty()){ SharedPreferences.Editor edit = settings.edit(); edit.putString("pref_password", makePassword()); edit.commit(); } - switch (themeId) { - case 1: - currentThemeId = R.style.AppTheme_NoActionBar; - break; - case 2: - currentThemeId = R.style.AppTheme_Dark; - break; - case 3: - currentThemeId = R.style.AppTheme_HeadLine; - setTheme(R.style.AppTheme_HeadLine_Activity); - break; - case 4: - currentThemeId = R.style.AppTheme_Black; - setTheme(R.style.AppTheme_Black_Activity); - break; - } - - themeManager = new ThemeManager(this); - Log.d("ThemeManager", "isDarkTheme: " + themeManager.isDarkTheme()); - setContentView(R.layout.activity_main); toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setTitle("Bievenido a internet"); this.setSupportActionBar(toolbar); - fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override @@ -372,25 +352,25 @@ public class MainActivity extends AppCompatActivity final SubMenu sub = menu.addSubMenu("Lista de Boards"); Ion.with(getApplicationContext()) .load("http://bienvenidoainternet.org/cgi/api/boards") - .asJsonObject() - .setCallback(new FutureCallback() { + .asString() + .setCallback(new FutureCallback() { @Override - public void onCompleted(Exception e, JsonObject result) { + public void onCompleted(Exception e, String result) { if (e != null) { e.printStackTrace(); Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show(); - } else { - JsonArray boards = result.get("boards").getAsJsonArray(); - for (int i = 0; i < boards.size(); i++) { - try { - JSONObject board = new JSONObject(boards.get(i).toString()); + }else { + try { + JSONArray boards = new JSONObject(result).getJSONArray("boards"); + for (int i = 0; i < boards.length(); i++) { + JSONObject board = boards.getJSONObject(i); Board parsedBoard = new Board(board.getString("name"), board.getString("dir"), board.getInt("board_type")); sub.add(parsedBoard.getBoardName()); boardList.add(parsedBoard); - } catch (JSONException e1) { - e1.printStackTrace(); - Toast.makeText(getApplicationContext(), "Error parsing JSON", Toast.LENGTH_LONG).show(); } + }catch (JSONException e1) { + Toast.makeText(getApplicationContext(), e1.getMessage(), Toast.LENGTH_LONG).show(); + e1.printStackTrace(); } } } -- cgit v1.2.1-18-gbd029