diff --git a/.gitignore b/.gitignore index d6bfc95..79b7f6c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /local.properties /.idea/workspace.xml .DS_Store +*.apk diff --git a/Technothlon.iml b/Technothlon.iml index 94f1c61..2140a04 100644 --- a/Technothlon.iml +++ b/Technothlon.iml @@ -1,6 +1,8 @@ - + + + diff --git a/app/app.iml b/app/app.iml index 6e04b6d..f04700e 100644 --- a/app/app.iml +++ b/app/app.iml @@ -25,37 +25,37 @@ - - - - - - + + + + + + + + + + + + + + + + - + + + + + - - - - - - - + + - - - - - - - - - diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 3667a16..4130157 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -27,6 +27,11 @@ android:launchMode="singleTask" android:taskAffinity="" > + + diff --git a/app/src/main/ic_launcher-web.png b/app/src/main/ic_launcher-web.png deleted file mode 100644 index 076f197..0000000 Binary files a/app/src/main/ic_launcher-web.png and /dev/null differ diff --git a/app/src/main/java/org/techniche/technothlon/katana/MainActivity.java b/app/src/main/java/org/techniche/technothlon/katana/MainActivity.java index 5b7a475..938458e 100644 --- a/app/src/main/java/org/techniche/technothlon/katana/MainActivity.java +++ b/app/src/main/java/org/techniche/technothlon/katana/MainActivity.java @@ -2,6 +2,7 @@ import android.app.Activity; import android.content.Context; +import android.content.Intent; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; @@ -107,8 +108,12 @@ public void finished() { } @Override - public void onTCDInteraction(String id) { - + public void onTCDInteraction(int id) { + Intent intent = new Intent(this, TCDSingleViewer.class); + Bundle bundle = new Bundle(); + bundle.putInt("open", id); + intent.putExtras(bundle); + startActivity(intent); } @Override diff --git a/app/src/main/java/org/techniche/technothlon/katana/TCDFragment.java b/app/src/main/java/org/techniche/technothlon/katana/TCDFragment.java index 7167d6c..1233ec1 100644 --- a/app/src/main/java/org/techniche/technothlon/katana/TCDFragment.java +++ b/app/src/main/java/org/techniche/technothlon/katana/TCDFragment.java @@ -86,7 +86,7 @@ public void onItemClick(AdapterView parent, View view, int position, long id) if (null != mListener) { // Notify the active callbacks interface (the activity, if the // fragment is attached to one) that an item has been selected. - mListener.onTCDInteraction(TCDContent.ITEMS.get(position).id); + mListener.onTCDInteraction(position); } } @@ -129,7 +129,7 @@ public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCoun * >Communicating with Other Fragments for more information. */ public interface OnTCDInteractionListener { - public void onTCDInteraction(String id); + public void onTCDInteraction(int id); } } diff --git a/app/src/main/java/org/techniche/technothlon/katana/TCDSingleViewer.java b/app/src/main/java/org/techniche/technothlon/katana/TCDSingleViewer.java new file mode 100644 index 0000000..2d4053f --- /dev/null +++ b/app/src/main/java/org/techniche/technothlon/katana/TCDSingleViewer.java @@ -0,0 +1,165 @@ +package org.techniche.technothlon.katana; + +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentPagerAdapter; +import android.support.v4.view.ViewPager; +import android.support.v7.app.ActionBarActivity; +import android.view.*; +import android.widget.TextView; +import org.techniche.technothlon.katana.tcd.TCDContent; + +import java.util.Locale; + +public class TCDSingleViewer extends ActionBarActivity implements ViewPager.OnPageChangeListener { + private static int pages; + /** + * The {@link android.support.v4.view.PagerAdapter} that will provide + * fragments for each of the sections. We use a + * {@link FragmentPagerAdapter} derivative, which will keep every + * loaded fragment in memory. If this becomes too memory intensive, it + * may be best to switch to a + * {@link android.support.v4.app.FragmentStatePagerAdapter}. + */ + SectionsPagerAdapter mSectionsPagerAdapter; + + /** + * The {@link ViewPager} that will host the section contents. + */ + ViewPager mViewPager; + private int activePage; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_tcdsingle_viewer); + // Create the adapter that will return a fragment for each of the three + // primary sections of the activity. + mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); + + pages = TCDContent.ITEMS.size(); + // Set up the ViewPager with the sections adapter. + mViewPager = (ViewPager) findViewById(R.id.pager); + mViewPager.setAdapter(mSectionsPagerAdapter); + activePage = getIntent().getExtras().getInt("open"); + mViewPager.setCurrentItem(activePage); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + + // Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.tcdsingle_viewer, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + int id = item.getItemId(); + if (id == R.id.action_settings) { + return true; + } + return super.onOptionsItemSelected(item); + } + + @Override + public void onPageScrolled(int i, float v, int i2) { + + } + + @Override + public void onPageSelected(int i) { + activePage = i; + } + + @Override + public void onPageScrollStateChanged(int i) { + + } + + + /** + * A {@link FragmentPagerAdapter} that returns a fragment corresponding to + * one of the sections/tabs/pages. + */ + public class SectionsPagerAdapter extends FragmentPagerAdapter { + + public SectionsPagerAdapter(FragmentManager fm) { + super(fm); + } + + @Override + public Fragment getItem(int position) { + // getItem is called to instantiate the fragment for the given page. + // Return a PlaceholderFragment (defined as a static inner class below). + return PlaceholderFragment.newInstance((position)); + } + + @Override + public int getCount() { + // Show 3 total pages. + return pages; + } + + @Override + public CharSequence getPageTitle(int position) { + Locale l = Locale.getDefault(); + TCDContent.TCDQuestion q = TCDContent.ITEM_MAP.get(TCDContent.ITEMS.get(position).id); + String title = "#"+q.id+" - "+q.title; + return title; + } + } + + /** + * A placeholder fragment containing a simple view. + */ + public static class PlaceholderFragment extends Fragment { + /** + * The fragment argument representing the section number for this + * fragment. + */ + private static final String ARG_SECTION_NUMBER = "section_number"; + + /** + * Returns a new instance of this fragment for the given section + * number. + */ + public static PlaceholderFragment newInstance(int sectionNumber) { + PlaceholderFragment fragment = new PlaceholderFragment(); + Bundle args = new Bundle(); + args.putInt(ARG_SECTION_NUMBER, sectionNumber); + fragment.setArguments(args); + return fragment; + } + + public PlaceholderFragment() { + } + + // TODO create view here + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.fragment_tcdsingle_viewer, container, false); + TextView id = (TextView) rootView.findViewById(R.id.tcd_id), + title = (TextView) rootView.findViewById(R.id.tcd_title), + question = (TextView) rootView.findViewById(R.id.tcd_question), + by = (TextView) rootView.findViewById(R.id.tcd_posted_by), + status = (TextView) rootView.findViewById(R.id.tcd_status); + int position = getArguments().getInt(ARG_SECTION_NUMBER); + TCDContent.TCDQuestion q = TCDContent.ITEM_MAP.get(TCDContent.ITEMS.get(position).id); + id.setText("#"+q.id); + id.setBackgroundResource(q.color); + title.setText(q.title); + question.setText(q.question); + by.setText(q.by); + status.setText(q.getStatus()); + return rootView; + } + } + +} diff --git a/app/src/main/java/org/techniche/technothlon/katana/tcd/TCDContent.java b/app/src/main/java/org/techniche/technothlon/katana/tcd/TCDContent.java index 38ee581..53c6482 100644 --- a/app/src/main/java/org/techniche/technothlon/katana/tcd/TCDContent.java +++ b/app/src/main/java/org/techniche/technothlon/katana/tcd/TCDContent.java @@ -165,13 +165,14 @@ public static void load(Context context) { TCDDatabase helper = new TCDDatabase(context); SQLiteDatabase db = helper.getReadableDatabase(); assert db != null; - Cursor c = db.rawQuery("SELECT * FROM " + TCDDatabase.Contracts.NAME + " ORDER BY " + TCDDatabase.Contracts.FIELD_TIME + " DESC", null); + Cursor c = db.rawQuery("SELECT * FROM " + TCDDatabase.Contracts.NAME + " ORDER BY " + TCDDatabase.Contracts.FIELD_TIME + " DESC, "+TCDDatabase.Contracts.FIELD_ID+ " DESC", null); Log.d("DB", c.getCount() + " object in database"); c.moveToFirst(); while (!c.isAfterLast()) { addItem(new TCDQuestion( c.getString(c.getColumnIndex(TCDDatabase.Contracts.FIELD_ID)), c.getString(c.getColumnIndex(TCDDatabase.Contracts.FIELD_DISPLAY_ID)), + c.getInt(c.getColumnIndex(TCDDatabase.Contracts.FIELD_COLOR)), c.getString(c.getColumnIndex(TCDDatabase.Contracts.FIELD_TITLE)), c.getString(c.getColumnIndex(TCDDatabase.Contracts.FIELD_QUESTION)), c.getString(c.getColumnIndex(TCDDatabase.Contracts.FIELD_FACEBOOK)), @@ -232,13 +233,13 @@ public static class TCDQuestion { public String title; public java.util.Date date = null; public String dateString = ""; - public int color = 1; + public int color = R.drawable.tcd_background_1; public String uniqueId; private String status; private boolean ret = false; - public TCDQuestion(String uniqueId, String id, String title, String question, String facebook, String google, String tumblr, + public TCDQuestion(String uniqueId, String id, int color, String title, String question, String facebook, String google, String tumblr, String answer_url, String by, String answer, String status) { this.uniqueId = uniqueId; @@ -250,6 +251,7 @@ public TCDQuestion(String uniqueId, String id, String title, String question, St this.tumblr = tumblr; this.answer_url = answer_url; this.by = by; + this.color = getBackground(color); this.answer = answer; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { @@ -261,6 +263,22 @@ public TCDQuestion(String uniqueId, String id, String title, String question, St this.dateString = sdf.format(this.date); this.status = getStatus(); } + private int getBackground(int color) { + switch (color) { + case 10: + return R.drawable.tcd_background_2; + case 20: + return R.drawable.tcd_background_3; + case 30: + return R.drawable.tcd_background_4; + case 40: + return R.drawable.tcd_background_5; + case 50: + return R.drawable.tcd_background_6; + default: + return R.drawable.tcd_background_1; + } + } public String getStatus() { if (ret) return status; diff --git a/app/src/main/java/org/techniche/technothlon/katana/tcd/TCDListAdapter.java b/app/src/main/java/org/techniche/technothlon/katana/tcd/TCDListAdapter.java index 7dbd5f6..71caef5 100644 --- a/app/src/main/java/org/techniche/technothlon/katana/tcd/TCDListAdapter.java +++ b/app/src/main/java/org/techniche/technothlon/katana/tcd/TCDListAdapter.java @@ -65,7 +65,7 @@ public View getView(int position, View convertView, ViewGroup parent) { holder.title.setText(question.title); holder.question.setText(question.question); holder.status.setText(question.getStatus()); - holder.id.setBackgroundResource(getBackground(question.color)); + holder.id.setBackgroundResource(question.color); } @@ -79,16 +79,4 @@ public View getView(int position, View convertView, ViewGroup parent) { return convertView; } - - private int getBackground(int color) { - switch (color) { - case 10: - case 20: - case 30: - case 40: - case 50: - default: - return R.drawable.tcd_background_1; - } - } } diff --git a/app/src/main/res/drawable-hdpi/ic_disqus.png b/app/src/main/res/drawable-hdpi/ic_disqus.png new file mode 100755 index 0000000..19662d0 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_disqus.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_facebook.png b/app/src/main/res/drawable-hdpi/ic_facebook.png new file mode 100755 index 0000000..144aee3 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_facebook.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_google.png b/app/src/main/res/drawable-hdpi/ic_google.png new file mode 100755 index 0000000..2b87ddb Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_google.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_launcher.png b/app/src/main/res/drawable-hdpi/ic_launcher.png old mode 100644 new mode 100755 index 7109597..f8e45d8 Binary files a/app/src/main/res/drawable-hdpi/ic_launcher.png and b/app/src/main/res/drawable-hdpi/ic_launcher.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_tumblr.png b/app/src/main/res/drawable-hdpi/ic_tumblr.png new file mode 100755 index 0000000..51af795 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_tumblr.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_twitter.png b/app/src/main/res/drawable-hdpi/ic_twitter.png new file mode 100755 index 0000000..a04e446 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_twitter.png differ diff --git a/app/src/main/res/drawable-hdpi/texture.png b/app/src/main/res/drawable-hdpi/texture.png new file mode 100644 index 0000000..1433128 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/texture.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_disqus.png b/app/src/main/res/drawable-mdpi/ic_disqus.png new file mode 100755 index 0000000..4f7c0b8 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_disqus.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_facebook.png b/app/src/main/res/drawable-mdpi/ic_facebook.png new file mode 100755 index 0000000..ed89029 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_facebook.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_google.png b/app/src/main/res/drawable-mdpi/ic_google.png new file mode 100755 index 0000000..bd505e9 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_google.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_launcher.png b/app/src/main/res/drawable-mdpi/ic_launcher.png old mode 100644 new mode 100755 index 7e0b7c9..77b6fcd Binary files a/app/src/main/res/drawable-mdpi/ic_launcher.png and b/app/src/main/res/drawable-mdpi/ic_launcher.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_tumblr.png b/app/src/main/res/drawable-mdpi/ic_tumblr.png new file mode 100755 index 0000000..9b39df3 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_tumblr.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_twitter.png b/app/src/main/res/drawable-mdpi/ic_twitter.png new file mode 100755 index 0000000..c887df8 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_twitter.png differ diff --git a/app/src/main/res/drawable-mdpi/texture.png b/app/src/main/res/drawable-mdpi/texture.png deleted file mode 100644 index 84479d5..0000000 Binary files a/app/src/main/res/drawable-mdpi/texture.png and /dev/null differ diff --git a/app/src/main/res/drawable-xhdpi/ic_disqus.png b/app/src/main/res/drawable-xhdpi/ic_disqus.png new file mode 100755 index 0000000..c6a3e1a Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_disqus.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_facebook.png b/app/src/main/res/drawable-xhdpi/ic_facebook.png new file mode 100755 index 0000000..2a588af Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_facebook.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_google.png b/app/src/main/res/drawable-xhdpi/ic_google.png new file mode 100755 index 0000000..53c2ca6 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_google.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_launcher.png b/app/src/main/res/drawable-xhdpi/ic_launcher.png old mode 100644 new mode 100755 index 59e263f..56da146 Binary files a/app/src/main/res/drawable-xhdpi/ic_launcher.png and b/app/src/main/res/drawable-xhdpi/ic_launcher.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_tumblr.png b/app/src/main/res/drawable-xhdpi/ic_tumblr.png new file mode 100755 index 0000000..4541b06 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_tumblr.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_twitter.png b/app/src/main/res/drawable-xhdpi/ic_twitter.png new file mode 100755 index 0000000..50b6b02 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_twitter.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_disqus.png b/app/src/main/res/drawable-xxhdpi/ic_disqus.png new file mode 100755 index 0000000..d485804 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_disqus.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_facebook.png b/app/src/main/res/drawable-xxhdpi/ic_facebook.png new file mode 100755 index 0000000..2fe2eec Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_facebook.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_google.png b/app/src/main/res/drawable-xxhdpi/ic_google.png new file mode 100755 index 0000000..5ea6a1d Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_google.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_launcher.png b/app/src/main/res/drawable-xxhdpi/ic_launcher.png old mode 100644 new mode 100755 index ee7113c..33f9507 Binary files a/app/src/main/res/drawable-xxhdpi/ic_launcher.png and b/app/src/main/res/drawable-xxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_tumblr.png b/app/src/main/res/drawable-xxhdpi/ic_tumblr.png new file mode 100755 index 0000000..db4b2dc Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_tumblr.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_twitter.png b/app/src/main/res/drawable-xxhdpi/ic_twitter.png new file mode 100755 index 0000000..30153b7 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_twitter.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_launcher.png b/app/src/main/res/drawable-xxxhdpi/ic_launcher.png new file mode 100755 index 0000000..edb74a4 Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/drawable/tcd_background_2.xml b/app/src/main/res/drawable/tcd_background_2.xml new file mode 100644 index 0000000..d5f523f --- /dev/null +++ b/app/src/main/res/drawable/tcd_background_2.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/tcd_background_3.xml b/app/src/main/res/drawable/tcd_background_3.xml new file mode 100644 index 0000000..e53292b --- /dev/null +++ b/app/src/main/res/drawable/tcd_background_3.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/tcd_background_4.xml b/app/src/main/res/drawable/tcd_background_4.xml new file mode 100644 index 0000000..bca7f75 --- /dev/null +++ b/app/src/main/res/drawable/tcd_background_4.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/tcd_background_5.xml b/app/src/main/res/drawable/tcd_background_5.xml new file mode 100644 index 0000000..678163f --- /dev/null +++ b/app/src/main/res/drawable/tcd_background_5.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/tcd_background_6.xml b/app/src/main/res/drawable/tcd_background_6.xml new file mode 100644 index 0000000..05ac61b --- /dev/null +++ b/app/src/main/res/drawable/tcd_background_6.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_tcdsingle_viewer.xml b/app/src/main/res/layout/activity_tcdsingle_viewer.xml new file mode 100644 index 0000000..dce389b --- /dev/null +++ b/app/src/main/res/layout/activity_tcdsingle_viewer.xml @@ -0,0 +1,6 @@ + diff --git a/app/src/main/res/layout/fragment_tcdsingle_viewer.xml b/app/src/main/res/layout/fragment_tcdsingle_viewer.xml new file mode 100644 index 0000000..0ea6e3d --- /dev/null +++ b/app/src/main/res/layout/fragment_tcdsingle_viewer.xml @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/menu/tcdsingle_viewer.xml b/app/src/main/res/menu/tcdsingle_viewer.xml new file mode 100644 index 0000000..ed589d8 --- /dev/null +++ b/app/src/main/res/menu/tcdsingle_viewer.xml @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f5ffba2..e34b86a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -14,5 +14,9 @@ katana_private technocoupdoeil_last_fetch_id Techno Coup D\'œil + Read on Facebook + Read on Google+ + Read on Tumblr + Discuss Answer diff --git a/app/src/main/web_hi_res_512.png b/app/src/main/web_hi_res_512.png new file mode 100755 index 0000000..764a2ec Binary files /dev/null and b/app/src/main/web_hi_res_512.png differ