Search in sources :

Example 1 with TeamHelper

use of com.supercilex.robotscouter.data.util.TeamHelper in project Robot-Scouter by SUPERCILEX.

the class SpreadsheetExporter method writeAndShareTeams.

/**
     * @return true if an export was attempted, false otherwise
     */
@SuppressWarnings("MissingPermission")
public static boolean writeAndShareTeams(Fragment fragment, PermissionRequestHandler permHandler, @Size(min = 1) List<TeamHelper> teamHelpers) {
    if (teamHelpers.isEmpty())
        return false;
    Context context = fragment.getContext();
    if (!EasyPermissions.hasPermissions(context, permHandler.getPermsArray())) {
        permHandler.requestPerms(R.string.write_storage_rationale_spreadsheet);
        return false;
    }
    if (shouldShowExportHint(context)) {
        Snackbar.make(fragment.getView(), R.string.exporting_spreadsheet_hint, Snackbar.LENGTH_INDEFINITE).setAction(R.string.never_again, v -> setShouldShowExportHint(context, false)).show();
    }
    fragment.getActivity().startService(new Intent(context, SpreadsheetExporter.class).putExtras(TeamHelper.toIntent(teamHelpers)));
    return true;
}
Also used : Context(android.content.Context) PreferencesUtilsKt.setShouldShowExportHint(com.supercilex.robotscouter.util.PreferencesUtilsKt.setShouldShowExportHint) SpreadsheetUtils.getMetricForScouts(com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.getMetricForScouts) ClientAnchor(org.apache.poi.ss.usermodel.ClientAnchor) Drawing(org.apache.poi.ss.usermodel.Drawing) Arrays(java.util.Arrays) Uri(android.net.Uri) DataSources(org.apache.poi.ss.usermodel.charts.DataSources) PreferencesUtilsKt.shouldShowExportHint(com.supercilex.robotscouter.util.PreferencesUtilsKt.shouldShowExportHint) IntentService(android.app.IntentService) NotificationForwarder(com.supercilex.robotscouter.data.client.NotificationForwarder) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Manifest(android.Manifest) ScatterChartData(org.apache.poi.ss.usermodel.charts.ScatterChartData) SpreadsheetUtils.createChartAnchor(com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.createChartAnchor) Map(java.util.Map) SpreadsheetUtils.showToast(com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.showToast) ChartAxis(org.apache.poi.ss.usermodel.charts.ChartAxis) NUMBER(com.supercilex.robotscouter.data.model.MetricTypeKt.NUMBER) XSSFChart(org.apache.poi.xssf.usermodel.XSSFChart) Sheet(org.apache.poi.ss.usermodel.Sheet) Fragment(android.support.v4.app.Fragment) ContextCompat(android.support.v4.content.ContextCompat) IoUtilsKt.unhideFile(com.supercilex.robotscouter.util.IoUtilsKt.unhideFile) ChartDataSource(org.apache.poi.ss.usermodel.charts.ChartDataSource) SpreadsheetUtils.getSafeSheetName(com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.getSafeSheetName) Snackbar(android.support.design.widget.Snackbar) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Scout(com.supercilex.robotscouter.data.model.Scout) IoUtilsKt.getRootFolder(com.supercilex.robotscouter.util.IoUtilsKt.getRootFolder) R(com.supercilex.robotscouter.R) Metric(com.supercilex.robotscouter.data.model.Metric) LineChartData(org.apache.poi.ss.usermodel.charts.LineChartData) SpreadsheetUtils.autoFitColumnWidths(com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.autoFitColumnWidths) ArrayList(java.util.ArrayList) SpreadsheetUtils.getChartRowIndex(com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.getChartRowIndex) AddTrace(com.google.firebase.perf.metrics.AddTrace) STOPWATCH(com.supercilex.robotscouter.data.model.MetricTypeKt.STOPWATCH) SpreadsheetUtils.setChartAxisTitle(com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.setChartAxisTitle) LIST(com.supercilex.robotscouter.data.model.MetricTypeKt.LIST) PluralsRes(android.support.annotation.PluralsRes) FileOutputStream(java.io.FileOutputStream) TextUtils(android.text.TextUtils) IOException(java.io.IOException) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) Workbook(org.apache.poi.ss.usermodel.Workbook) ValueAxis(org.apache.poi.ss.usermodel.charts.ValueAxis) AxisCrosses(org.apache.poi.ss.usermodel.charts.AxisCrosses) IoUtilsKt.hideFile(com.supercilex.robotscouter.util.IoUtilsKt.hideFile) Scouts(com.supercilex.robotscouter.data.util.Scouts) AnalyticsUtilsKt.logExportTeamsEvent(com.supercilex.robotscouter.util.AnalyticsUtilsKt.logExportTeamsEvent) Chart(org.apache.poi.ss.usermodel.Chart) ConstantsKt.providerAuthorityJava(com.supercilex.robotscouter.util.ConstantsKt.providerAuthorityJava) TimeoutException(java.util.concurrent.TimeoutException) PendingIntent(android.app.PendingIntent) FileProvider(android.support.v4.content.FileProvider) TEXT(com.supercilex.robotscouter.data.model.MetricTypeKt.TEXT) SpreadsheetUtils.getAdjustedList(com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.getAdjustedList) Cell(org.apache.poi.ss.usermodel.Cell) CTChart(org.openxmlformats.schemas.drawingml.x2006.chart.CTChart) ConnectivityUtilsKt.isOffline(com.supercilex.robotscouter.util.ConnectivityUtilsKt.isOffline) AxisPosition(org.apache.poi.ss.usermodel.charts.AxisPosition) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) LegendPosition(org.apache.poi.ss.usermodel.charts.LegendPosition) SINGLE_ITEM(com.supercilex.robotscouter.util.ConstantsKt.SINGLE_ITEM) RichTextString(org.apache.poi.ss.usermodel.RichTextString) FirebaseCrash(com.google.firebase.crash.FirebaseCrash) SpreadsheetUtils.getStringForCell(com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.getStringForCell) RequiresPermission(android.support.annotation.RequiresPermission) WorkbookEvaluator(org.apache.poi.ss.formula.WorkbookEvaluator) SpreadsheetUtils.showError(com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.showError) PermissionRequestHandler(com.supercilex.robotscouter.ui.PermissionRequestHandler) List(java.util.List) Tasks(com.google.android.gms.tasks.Tasks) Notification(android.app.Notification) Nullable(android.support.annotation.Nullable) EasyPermissions(pub.devrel.easypermissions.EasyPermissions) Context(android.content.Context) CellType(org.apache.poi.ss.usermodel.CellType) SpreadsheetUtils.getCellRangeAddress(com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.getCellRangeAddress) Pair(android.util.Pair) SpreadsheetUtils.isUnsupportedDevice(com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.isUnsupportedDevice) Intent(android.content.Intent) HashMap(java.util.HashMap) CTPlotArea(org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea) TeamHelper(com.supercilex.robotscouter.data.util.TeamHelper) MissingCellPolicy(org.apache.poi.ss.usermodel.Row.MissingCellPolicy) ChartLegend(org.apache.poi.ss.usermodel.charts.ChartLegend) Build(android.os.Build) Iterator(java.util.Iterator) BOOLEAN(com.supercilex.robotscouter.data.model.MetricTypeKt.BOOLEAN) Size(android.support.annotation.Size) TimeUnit(java.util.concurrent.TimeUnit) HEADER(com.supercilex.robotscouter.data.model.MetricTypeKt.HEADER) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) SpreadsheetUtils.getMetricForChart(com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.getMetricForChart) NotificationCompat(android.support.v4.app.NotificationCompat) Row(org.apache.poi.ss.usermodel.Row) Collections(java.util.Collections) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent)

Example 2 with TeamHelper

use of com.supercilex.robotscouter.data.util.TeamHelper in project Robot-Scouter by SUPERCILEX.

the class TeamMenuHelper method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    TeamHelper teamHelper = mSelectedTeams.get(0);
    switch(item.getItemId()) {
        case R.id.action_export_spreadsheet:
            exportTeams();
            break;
        case R.id.action_share:
            if (TeamSharer.launchInvitationIntent(mFragment.getActivity(), mSelectedTeams)) {
                resetMenu();
            }
            logShareTeamEvent(teamHelper.getTeam().getNumber());
            break;
        case R.id.action_visit_tba_website:
            teamHelper.visitTbaWebsite(mFragment.getContext());
            resetMenu();
            break;
        case R.id.action_visit_team_website:
            teamHelper.visitTeamWebsite(mFragment.getContext());
            resetMenu();
            break;
        case R.id.action_edit_team_details:
            TeamDetailsDialog.show(mFragment.getChildFragmentManager(), teamHelper);
            logEditTeamDetailsEvent(teamHelper.getTeam().getNumber());
            break;
        case R.id.action_delete:
            DeleteTeamDialog.Companion.show(mFragment.getChildFragmentManager(), mSelectedTeams);
            break;
        case android.R.id.home:
            resetMenu();
            break;
        default:
            return false;
    }
    return true;
}
Also used : TeamHelper(com.supercilex.robotscouter.data.util.TeamHelper)

Example 3 with TeamHelper

use of com.supercilex.robotscouter.data.util.TeamHelper in project Robot-Scouter by SUPERCILEX.

the class SpreadsheetExporter method getWorkbook.

@AddTrace(name = "getWorkbook")
private Workbook getWorkbook() {
    Workbook workbook;
    if (isUnsupportedDevice()) {
        workbook = new HSSFWorkbook();
        showToast(this, getString(R.string.unsupported_device));
    } else {
        workbook = new XSSFWorkbook();
    }
    mCache.setWorkbook(workbook);
    Sheet averageSheet = null;
    if (mCache.getTeamHelpers().size() > SINGLE_ITEM) {
        averageSheet = workbook.createSheet("Team Averages");
        averageSheet.createFreezePane(1, 1);
    }
    List<TeamHelper> teamHelpers = mCache.getTeamHelpers();
    for (TeamHelper teamHelper : teamHelpers) {
        mCache.updateNotification(getString(R.string.exporting_spreadsheet_team, teamHelper));
        Sheet teamSheet = workbook.createSheet(getSafeSheetName(workbook, teamHelper));
        teamSheet.createFreezePane(1, 1);
        buildTeamSheet(teamHelper, teamSheet);
    }
    mCache.updateNotification(getString(R.string.exporting_spreadsheet_average));
    if (averageSheet != null)
        buildTeamAveragesSheet(averageSheet);
    mCache.updateNotification(getString(R.string.exporting_spreadsheet_cleanup));
    autoFitColumnWidths(workbook);
    return workbook;
}
Also used : XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) TeamHelper(com.supercilex.robotscouter.data.util.TeamHelper) Sheet(org.apache.poi.ss.usermodel.Sheet) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) AddTrace(com.google.firebase.perf.metrics.AddTrace)

Example 4 with TeamHelper

use of com.supercilex.robotscouter.data.util.TeamHelper in project Robot-Scouter by SUPERCILEX.

the class ScoutTemplateSheet method getTemplateKey.

private void getTemplateKey() {
    TeamHelper teamHelper = TeamHelper.parse(getArguments());
    mTemplateKey = teamHelper.getTeam().getTemplateKey();
    if (TextUtils.isEmpty(mTemplateKey)) {
        if (!Constants.sFirebaseScoutTemplates.isEmpty()) {
            mTemplateKey = Constants.sFirebaseScoutTemplates.get(0).getKey();
            teamHelper.updateTemplateKey(mTemplateKey);
            return;
        }
        DatabaseReference newTemplateRef = FIREBASE_SCOUT_TEMPLATES.push();
        mTemplateKey = newTemplateRef.getKey();
        FirebaseCopier.copyTo(Constants.sDefaultTemplate, newTemplateRef);
        teamHelper.updateTemplateKey(mTemplateKey);
        UserHelper.getScoutTemplateIndicesRef().child(mTemplateKey).setValue(true);
        for (int i = 0; i < Constants.sFirebaseTeams.size(); i++) {
            Team team = Constants.sFirebaseTeams.getObject(i);
            String templateKey = team.getTemplateKey();
            if (TextUtils.isEmpty(templateKey)) {
                team.getHelper().updateTemplateKey(mTemplateKey);
            }
        }
    }
}
Also used : DatabaseReference(com.google.firebase.database.DatabaseReference) TeamHelper(com.supercilex.robotscouter.data.util.TeamHelper) Team(com.supercilex.robotscouter.data.model.Team)

Aggregations

TeamHelper (com.supercilex.robotscouter.data.util.TeamHelper)4 AddTrace (com.google.firebase.perf.metrics.AddTrace)2 Manifest (android.Manifest)1 IntentService (android.app.IntentService)1 Notification (android.app.Notification)1 PendingIntent (android.app.PendingIntent)1 Context (android.content.Context)1 Intent (android.content.Intent)1 Uri (android.net.Uri)1 Build (android.os.Build)1 Nullable (android.support.annotation.Nullable)1 PluralsRes (android.support.annotation.PluralsRes)1 RequiresPermission (android.support.annotation.RequiresPermission)1 Size (android.support.annotation.Size)1 Snackbar (android.support.design.widget.Snackbar)1 Fragment (android.support.v4.app.Fragment)1 NotificationCompat (android.support.v4.app.NotificationCompat)1 ContextCompat (android.support.v4.content.ContextCompat)1 FileProvider (android.support.v4.content.FileProvider)1 TextUtils (android.text.TextUtils)1