Added Generic and Specific Fragments

Generic Fragment Layout was defined
Specific Laout Object wer integrated including all object specific handling
FragmentObjects can now be added to ListViews.
Possible clean solution would be to have a PagingAdapter for each object type.
This commit is contained in:
Alexander Doerflinger
2017-08-10 10:11:29 +02:00
parent 8967107045
commit 9494c081d1
11 changed files with 755 additions and 4 deletions

2
.idea/misc.xml generated
View File

@@ -56,7 +56,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View File

@@ -70,7 +70,7 @@ public class DatabaseHandler extends SQLiteAssetHelper {
values.put(Constants.KEY_GAME, track.getGame());
values.put(Constants.KEY_NAME, track.getName());
values.put(Constants.KEY_PACKAGE, track.getPackage());
values.put(Constants.KEY_NUMBER, track.getmNumber());
values.put(Constants.KEY_NUMBER, track.getNumber());
if (isAvailable) {
values.put(Constants.KEY_AVAILABLE, String.valueOf(Constants.TRUE));
} else {

View File

@@ -152,7 +152,7 @@ public class Track {
*
* @return the number of the track within the package.
*/
public int getmNumber() {
public int getNumber() {
return mNumber;
}
@@ -161,7 +161,7 @@ public class Track {
*
* @param number the number of the track within the package.
*/
public void setmNumber(int number) {
public void setNumber(int number) {
mNumber = number;
}

View File

@@ -0,0 +1,124 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector.fragments;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import com.de.aldo_apps.aldo.mariokartcircuitselector.DatabaseHandler;
import com.de.aldo_apps.aldo.mariokartcircuitselector.R;
import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Accessory;
/**
* The SingleAccessoryFragment which displays all information of a single accessory object. Also
* this fragment handles the onClick. Based on the Click we will toggle the availability of this
* object in the database.
*
* @author aldo7224
* @version 0.1
* @since 10.08.2017
*/
public class SingleAccessoryFragment extends Fragment {
/**
* The Tag for Debugging Output.
*/
private static final String TAG = "SingleAccessoryFragment";
/**
* Checkbox indicating the current availability status of the single accessory object.
*/
private CheckBox mAccessoryAvailable;
/**
* TextView displaying the name of the single accessory object.
*/
private TextView mAccessoryName;
/**
* The accessory object assigned to this fragment.
*/
private Accessory mAccessory;
/**
* The Database handler passed from the activity to handle database operations.
*/
private DatabaseHandler mHandler;
@Override
public View onCreateView(final LayoutInflater inflater,
final ViewGroup container,
final Bundle savedInstanceState) {
// Inflate the GenericListItem and return it. All Operations on the View will be handled
// in own functions.
return inflater.inflate(R.layout.generic_list_item, container, false);
}
@Override
public void onViewCreated(final View view, final Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// Initialize the Views and member variables.
// Make all the Visible/Invisible/Gone Actions here as we know which information will be
// shown here.
initViews(view);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
if (mAccessoryAvailable != null) {
mAccessoryAvailable.toggle();
}
}
});
}
/**
* Helper method to initialize all View objects and toggle the visibility as we now know which
* object should be passed into the fragment.
*
* @param view The Parent View.
*/
private void initViews(final View view) {
mAccessoryAvailable = (CheckBox) view.findViewById(R.id.availability_checkbox);
// Assign a CheckedChange Listener to the Checkbox, so we can update the status in the
// database as well.
mAccessoryAvailable.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton compoundButton,
final boolean availability) {
if (mHandler != null && mAccessory != null) {
mHandler.changeAccessoryAvailability(mAccessory, availability);
} else {
Log.d(TAG, "onCheckedChanged: Either Handler or Accessory are null!");
}
}
});
// Mark the Container as GONE.
final View additionalInfoContainer = view.findViewById(R.id.multiple_information_container);
additionalInfoContainer.setVisibility(View.GONE);
// Initialize all single views and make them visible.
mAccessoryName = (TextView) view.findViewById(R.id.single_info_name);
mAccessoryName.setVisibility(View.VISIBLE);
}
/**
* Helper method which sets the real texts/arguments to the view objects.
*
* @param accessory The Accessory object of which we will retrieve our texts/arguments.
* @param handler The Database handler which handles the database operations.
*/
public void setArguments(final Accessory accessory, final DatabaseHandler handler) {
mAccessory = accessory;
mHandler = handler;
mAccessoryAvailable.setChecked(accessory.getAvailable());
mAccessoryName.setText(accessory.getName());
}
}

View File

@@ -0,0 +1,140 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector.fragments;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import com.de.aldo_apps.aldo.mariokartcircuitselector.DatabaseHandler;
import com.de.aldo_apps.aldo.mariokartcircuitselector.R;
import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Character;
/**
* The SingleCharacterFragment which displays all information of a single character object. Also
* this fragment handles the onClick. Based on the Click we will toggle the availability of this
* object in the database.
*
* @author aldo7224
* @version 0.1
* @since 10.08.2017
*/
public class SingleCharacterFragment extends Fragment {
/**
* The Tag for Debugging Output.
*/
private static final String TAG = "SingleCharacterFragment";
/**
* Checkbox indicating the current availability status of the single character object.
*/
private CheckBox mCharacterAvailable;
/**
* TextView displaying the name of the single character object.
*/
private TextView mCharacterName;
/**
* TextView displaying the package (Cup) of the single character object.
*/
private TextView mCharacterWeight;
/**
* The character object assigned to this fragment.
*/
private Character mCharacter;
/**
* The Database handler passed from the activity to handle database operations.
*/
private DatabaseHandler mHandler;
@Override
public View onCreateView(final LayoutInflater inflater,
final ViewGroup container,
final Bundle savedInstanceState) {
// Inflate the GenericListItem and return it. All Operations on the View will be handled
// in own functions.
return inflater.inflate(R.layout.generic_list_item, container, false);
}
@Override
public void onViewCreated(final View view, final Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// Initialize the Views and member variables.
// Make all the Visible/Invisible/Gone Actions here as we know which information will be
// shown here.
initViews(view);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
if (mCharacterAvailable != null) {
mCharacterAvailable.toggle();
}
}
});
}
/**
* Helper method to initialize all View objects and toggle the visibility as we now know which
* object should be passed into the fragment.
*
* @param view The Parent View.
*/
private void initViews(final View view) {
mCharacterAvailable = (CheckBox) view.findViewById(R.id.availability_checkbox);
// Assign a CheckedChange Listener to the Checkbox, so we can update the status in the
// database as well.
mCharacterAvailable.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton compoundButton,
final boolean availability) {
if (mHandler != null && mCharacter != null) {
mHandler.changeCharacterAvailability(mCharacter, availability);
} else {
Log.d(TAG, "onCheckedChanged: Either Handler or Character are null!");
}
}
});
// Make the Container Visible.
final View additionalInfoContainer = view.findViewById(R.id.multiple_information_container);
additionalInfoContainer.setVisibility(View.VISIBLE);
// Initialize all single views and make them visible.
mCharacterName = (TextView) view.findViewById(R.id.multi_view_name);
mCharacterWeight = (TextView) view.findViewById(R.id.additional_info_first);
mCharacterWeight.setVisibility(View.VISIBLE);
final View separator = view.findViewById(R.id.additional_information_separator);
separator.setVisibility(View.GONE);
final View secondInfo = view.findViewById(R.id.additional_info_second);
secondInfo.setVisibility(View.GONE);
// Mark the single name view (without additional information) as GONE
final View singleName = view.findViewById(R.id.single_info_name);
singleName.setVisibility(View.GONE);
}
/**
* Helper method which sets the real texts/arguments to the view objects.
*
* @param character The Character object of which we will retrieve our texts/arguments.
* @param handler The Database handler which handles the database operations.
*/
public void setArguments(final Character character, final DatabaseHandler handler) {
mCharacter = character;
mHandler = handler;
mCharacterAvailable.setChecked(character.getAvailable());
mCharacterName.setText(character.getName());
mCharacterWeight.setText(character.getWeight());
}
}

View File

@@ -0,0 +1,146 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector.fragments;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import com.de.aldo_apps.aldo.mariokartcircuitselector.DatabaseHandler;
import com.de.aldo_apps.aldo.mariokartcircuitselector.R;
import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Kart;
/**
* The SingleKartFragment which displays all information of a single kart object. Also this fragment
* handles the onClick. Based on the Click we will toggle the availability of this object in the
* database.
*
* @author aldo7224
* @version 0.1
* @since 10.08.2017
*/
public class SingleKartFragment extends Fragment {
/**
* The Tag for Debugging Output.
*/
private static final String TAG = "SingleKartFragment";
/**
* Checkbox indicating the current availability status of the single kart object.
*/
private CheckBox mKartAvailable;
/**
* TextView displaying the name of the single kart object.
*/
private TextView mKartName;
/**
* TextView displaying the weight of the single kart object.
*/
private TextView mKartWeight;
/**
* TextView displaying the dedicated Driver of the single kart object.
*/
private TextView mKartDedicatedDriver;
/**
* The kart object assigned to this fragment.
*/
private Kart mKart;
/**
* The Database handler passed from the activity to handle database operations.
*/
private DatabaseHandler mHandler;
@Override
public View onCreateView(final LayoutInflater inflater,
final ViewGroup container,
final Bundle savedInstanceState) {
// Inflate the GenericListItem and return it. All Operations on the View will be handled
// in own functions.
return inflater.inflate(R.layout.generic_list_item, container, false);
}
@Override
public void onViewCreated(final View view, final Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// Initialize the Views and member variables.
// Make all the Visible/Invisible/Gone Actions here as we know which information will be
// shown here.
initViews(view);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
if (mKartAvailable != null) {
mKartAvailable.toggle();
}
}
});
}
/**
* Helper method to initialize all View objects and toggle the visibility as we now know which
* object should be passed into the fragment.
*
* @param view The Parent View.
*/
private void initViews(final View view) {
mKartAvailable = (CheckBox) view.findViewById(R.id.availability_checkbox);
// Assign a CheckedChange Listener to the Checkbox, so we can update the status in the
// database as well.
mKartAvailable.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton compoundButton,
final boolean availability) {
if (mHandler != null && mKart != null) {
mHandler.changeKartAvailability(mKart, availability);
} else {
Log.d(TAG, "onCheckedChanged: Either Handler or Kart are null!");
}
}
});
// Make the Container Visible.
final View additionalInfoContainer = view.findViewById(R.id.multiple_information_container);
additionalInfoContainer.setVisibility(View.VISIBLE);
// Initialize all single views and make them visible.
mKartName = (TextView) view.findViewById(R.id.multi_view_name);
mKartWeight = (TextView) view.findViewById(R.id.additional_info_first);
mKartWeight.setVisibility(View.VISIBLE);
final View separator = view.findViewById(R.id.additional_information_separator);
separator.setVisibility(View.VISIBLE);
mKartDedicatedDriver = (TextView) view.findViewById(R.id.additional_info_second);
mKartDedicatedDriver.setVisibility(View.VISIBLE);
// Mark the single name view (without additional information) as GONE
final View singleName = view.findViewById(R.id.single_info_name);
singleName.setVisibility(View.GONE);
}
/**
* Helper method which sets the real texts/arguments to the view objects.
*
* @param kart The Kart object of which we will retrieve our texts/arguments.
* @param handler The Database handler which handles the database operations.
*/
public void setArguments(final Kart kart, final DatabaseHandler handler) {
mKart = kart;
mHandler = handler;
mKartAvailable.setChecked(kart.getAvailable());
mKartName.setText(kart.getName());
mKartWeight.setText(kart.getWeight());
mKartDedicatedDriver.setText(kart.getDedicatedDriver());
}
}

View File

@@ -0,0 +1,145 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector.fragments;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import com.de.aldo_apps.aldo.mariokartcircuitselector.DatabaseHandler;
import com.de.aldo_apps.aldo.mariokartcircuitselector.R;
import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Track;
/**
* The SingleTrackFragment which displays all information of a single track object. Also this
* fragment handles the onClick. Based on the Click we will toggle the availability of this object
* in the database.
*
* @author aldo7224
* @version 0.1
* @since 10.08.2017
*/
public class SingleTrackFragment extends Fragment {
/**
* The Tag for Debugging Output.
*/
private static final String TAG = "SingleTrackFragment";
/**
* Checkbox indicating the current availability status of the single track object.
*/
private CheckBox mTrackAvailable;
/**
* TextView displaying the name of the single track object.
*/
private TextView mTrackName;
/**
* TextView displaying the package (Cup) of the single track object.
*/
private TextView mTrackPackage;
/**
* TextView displaying the number of the single track object.
*/
private TextView mTrackNumber;
/**
* The track object assigned to this fragment.
*/
private Track mTrack;
/**
* The Database handler passed from the activity to handle database operations.
*/
private DatabaseHandler mHandler;
@Override
public View onCreateView(final LayoutInflater inflater,
final ViewGroup container,
final Bundle savedInstanceState) {
// Inflate the GenericListItem and return it. All Operations on the View will be handled
// in own functions.
return inflater.inflate(R.layout.generic_list_item, container, false);
}
@Override
public void onViewCreated(final View view, final Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// Initialize the Views and member variables.
// Make all the Visible/Invisible/Gone Actions here as we know which information will be
// shown here.
initViews(view);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
if (mTrackAvailable != null) {
mTrackAvailable.toggle();
}
}
});
}
/**
* Helper method to initialize all View objects and toggle the visibility as we now know which
* object should be passed into the fragment.
*
* @param view The Parent View.
*/
private void initViews(final View view) {
mTrackAvailable = (CheckBox) view.findViewById(R.id.availability_checkbox);
// Assign a CheckedChange Listener to the Checkbox, so we can update the status in the
// database as well.
mTrackAvailable.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton compoundButton,
final boolean availability) {
if (mHandler != null && mTrack != null) {
mHandler.changeTrackAvailability(mTrack, availability);
} else {
Log.d(TAG, "onCheckedChanged: Either Handler or Track are null!");
}
}
});
// Make the Container Visible.
final View additionalInfoContainer = view.findViewById(R.id.multiple_information_container);
additionalInfoContainer.setVisibility(View.VISIBLE);
// Initialize all single views and make them visible.
mTrackName = (TextView) view.findViewById(R.id.multi_view_name);
mTrackPackage = (TextView) view.findViewById(R.id.additional_info_first);
mTrackPackage.setVisibility(View.VISIBLE);
final View separator = view.findViewById(R.id.additional_information_separator);
separator.setVisibility(View.VISIBLE);
mTrackNumber = (TextView) view.findViewById(R.id.additional_info_second);
mTrackNumber.setVisibility(View.VISIBLE);
// Mark the single name view (without additional information) as GONE
final View singleName = view.findViewById(R.id.single_info_name);
singleName.setVisibility(View.GONE);
}
/**
* Helper method which sets the real texts/arguments to the view objects.
*
* @param track The Track object of which we will retrieve our texts/arguments.
* @param handler The Database handler which handles the database operations.
*/
public void setArguments(final Track track, final DatabaseHandler handler) {
mTrack = track;
mHandler = handler;
mTrackAvailable.setChecked(track.getAvailable());
mTrackName.setText(track.getName());
mTrackPackage.setText(track.getPackage());
mTrackNumber.setText(track.getNumber());
}
}

View File

@@ -0,0 +1,125 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector.fragments;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import com.de.aldo_apps.aldo.mariokartcircuitselector.DatabaseHandler;
import com.de.aldo_apps.aldo.mariokartcircuitselector.R;
import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Wheels;
/**
* The SingleWheelsFragment which displays all information of a single wheels object. Also this
* fragment handles the onClick. Based on the Click we will toggle the availability of this object
* in the database.
*
* @author aldo7224
* @version 0.1
* @since 10.08.2017
*/
public class SingleWheelsFragment extends Fragment {
/**
* The Tag for Debugging Output.
*/
private static final String TAG = "SingleWheelsFragment";
/**
* Checkbox indicating the current availability status of the single wheels object.
*/
private CheckBox mWheelsAvailable;
/**
* TextView displaying the name of the single wheels object.
*/
private TextView mWheelsName;
/**
* The wheels object assigned to this fragment.
*/
private Wheels mWheels;
/**
* The Database handler passed from the activity to handle database operations.
*/
private DatabaseHandler mHandler;
@Override
public View onCreateView(final LayoutInflater inflater,
final ViewGroup container,
final Bundle savedInstanceState) {
// Inflate the GenericListItem and return it. All Operations on the View will be handled
// in own functions.
return inflater.inflate(R.layout.generic_list_item, container, false);
}
@Override
public void onViewCreated(final View view, final Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// Initialize the Views and member variables.
// Make all the Visible/Invisible/Gone Actions here as we know which information will be
// shown here.
initViews(view);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
if (mWheelsAvailable != null) {
mWheelsAvailable.toggle();
}
}
});
}
/**
* Helper method to initialize all View objects and toggle the visibility as we now know which
* object should be passed into the fragment.
*
* @param view The Parent View.
*/
private void initViews(final View view) {
mWheelsAvailable = (CheckBox) view.findViewById(R.id.availability_checkbox);
// Assign a CheckedChange Listener to the Checkbox, so we can update the status in the
// database as well.
mWheelsAvailable.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton compoundButton,
final boolean availability) {
if (mHandler != null && mWheels != null) {
mHandler.changeWheelsAvailability(mWheels, availability);
} else {
Log.d(TAG, "onCheckedChanged: Either Handler or Wheels are null!");
}
}
});
// Mark the Container as GONE.
final View additionalInfoContainer = view.findViewById(R.id.multiple_information_container);
additionalInfoContainer.setVisibility(View.GONE);
// Initialize all single views and make them visible.
mWheelsName = (TextView) view.findViewById(R.id.single_info_name);
mWheelsName.setVisibility(View.VISIBLE);
}
/**
* Helper method which sets the real texts/arguments to the view objects.
*
* @param wheels The Wheels object of which we will retrieve our texts/arguments.
* @param handler The Database handler which handles the database operations.
*/
public void setArguments(final Wheels wheels, final DatabaseHandler handler) {
mWheels = wheels;
mHandler = handler;
mWheelsAvailable.setChecked(wheels.getAvailable());
mWheelsName.setText(wheels.getName());
}
}

View File

@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_centerHorizontal="true">
<!-- CheckBox indicating the current availability status -->
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/availability_checkbox"/>
<!-- LinearLayout container which holds multiple TextViews for multiple information
(e.g. name and weight) -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/multiple_information_container">
<!-- The TextView containing the objects name -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/multi_view_name" />
<!-- LinearLayout which aligns the additional information properly -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!-- TextView holding the first value (e.g. weight) -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/additional_info_first" />
<!-- TextView which has a function as a separator between the first and the second
value -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/additional_information_separator"
android:layout_marginLeft="@dimen/separator_margin"
android:layout_marginRight="@dimen/separator_margin"
android:text="@string/separator"/>
<!-- TextView holding the second value (e.g. dedicated driver) -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/additional_info_second"
/>
</LinearLayout>
</LinearLayout>
<!-- TextView which simply holds a name without additional information -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/single_info_name"
android:visibility="gone"/>
</LinearLayout>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="separator_margin">10dp</dimen>
</resources>

View File

@@ -1,3 +1,5 @@
<resources>
<string name="app_name">MarioKartCircuitSelector</string>
<string name="separator">-</string>
</resources>