Java tutorial
/** Copyright (c) 2014 Jordi Lpez <@wuyingren> * * MIT License: * * 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 cat.wuyingren.rorhelper.fragments; import android.content.Context; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.support.v7.widget.DefaultItemAnimator; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import cat.wuyingren.rorhelper.R; import cat.wuyingren.rorhelper.activities.MainActivity; import cat.wuyingren.rorhelper.profiles.Game; import cat.wuyingren.rorhelper.sql.GameDataSource; import cat.wuyingren.rorhelper.utils.FactionAdapter; /** * Created by jordilb on 28/10/14. */ public class GameFactionFragment extends Fragment { public static final String ARG_FACTION_ID = "faction_id"; public static final String ARG_GAME_ID = "game_id"; private Context context; private GameDataSource dataSource; private Game currentGame; private long gameID; private long factionID; private RecyclerView mRecyclerView; private FactionAdapter mAdapter; public GameFactionFragment() { } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); context = MainActivity.getContext(); dataSource = MainActivity.getDataSource(); /*dataSource = new GameDataSource(context); dataSource.open();*/ gameID = getArguments().getLong(ARG_GAME_ID); factionID = getArguments().getLong(ARG_FACTION_ID); Log.w("TAG", "showing info for faction " + factionID + " on game " + gameID); currentGame = dataSource.getGameById(gameID); } @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_faction, container, false); mRecyclerView = (RecyclerView) rootView.findViewById(R.id.list); return rootView; } @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mRecyclerView.setLayoutManager(new LinearLayoutManager(context)); mRecyclerView.setItemAnimator(new DefaultItemAnimator()); mAdapter = new FactionAdapter(dataSource.getAllSenatorsOfFaction(factionID), R.layout.cards_faction, context, gameID); mRecyclerView.setAdapter(mAdapter); } }