/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Devcon Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.devconmyanmar.apps.devcon.ui;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import butterknife.Bind;
import butterknife.ButterKnife;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.devconmyanmar.apps.devcon.R;
import org.devconmyanmar.apps.devcon.adapter.MyPagerAdapter;
import org.devconmyanmar.apps.devcon.model.Talk;
import org.devconmyanmar.apps.devcon.transformer.StackTransformer;
import org.devconmyanmar.apps.devcon.utils.HelpUtils;
import static org.devconmyanmar.apps.devcon.Config.POSITION;
public class TalkDetailActivity extends BaseActivity {
@Bind(R.id.schedule_pager) ViewPager mScheduleViewPager;
@Bind(R.id.toolbar) Toolbar mToolbar;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_schedule_detail);
ButterKnife.bind(this);
setSupportActionBar(mToolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setTitle(R.string.title_activity_schedule_detail);
actionBar.setDisplayHomeAsUpEnabled(true);
}
Intent intent = getIntent();
int position = intent.getIntExtra(POSITION, 0) - 1;
List<Fragment> fragments = getTalkFragments();
MyPagerAdapter mAdapter = new MyPagerAdapter(getSupportFragmentManager(), fragments);
mScheduleViewPager.setPageTransformer(true, new StackTransformer());
mScheduleViewPager.setAdapter(mAdapter);
mScheduleViewPager.setCurrentItem(position);
}
@Override public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.schedule_menu, menu);
return super.onCreateOptionsMenu(menu);
}
@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();
switch (id) {
case R.id.action_about:
HelpUtils.showAbout(this);
return true;
case android.R.id.home:
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private List<Fragment> getTalkFragments() {
List<Fragment> fList = new ArrayList<Fragment>();
try {
List<Talk> talks = talkDao.getAll();
for (Talk talk : talks) {
int talkId = talk.getId();
fList.add(TalkDetailFragment.newInstance(String.valueOf(talkId)));
}
} catch (SQLException e) {
e.printStackTrace();
}
return fList;
}
}